Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中放弃部分函数输出?_Python_Output - Fatal编程技术网

如何在python中放弃部分函数输出?

如何在python中放弃部分函数输出?,python,output,Python,Output,假设我在python中有一个函数,它返回一对(text,rc)。在某些情况下,我想使用这两个部分,但在某些情况下,我只想使用其中一个。在python中,是否有与以下语法类似的语法 text, rc = f() # read both, text and rc text, ~ = = f() # read only text ~, rc = = f() # read only rc 一种常见的Python习惯用法是将\uuu用作伪变量: text,rc = f() text,_ = f() _,

假设我在python中有一个函数,它返回一对(text,rc)。在某些情况下,我想使用这两个部分,但在某些情况下,我只想使用其中一个。在python中,是否有与以下语法类似的语法

text, rc = f() # read both, text and rc
text, ~ = = f() # read only text
~, rc = = f() # read only rc

一种常见的Python习惯用法是将
\uuu
用作伪变量:

text,rc = f()
text,_ = f()
_,rc = f()
或者您可以使用:

text,rc = f()
text = f()[0]
rc = f()[1]
您甚至可以使用多个:

_,_,_,x = method_returning_4_args_and_only_want_the_last()

一种常见的Python习惯用法是将
\uuu
用作伪变量:

text,rc = f()
text,_ = f()
_,rc = f()
或者您可以使用:

text,rc = f()
text = f()[0]
rc = f()[1]
您甚至可以使用多个:

_,_,_,x = method_returning_4_args_and_only_want_the_last()

一种常见的Python习惯用法是将
\uuu
用作伪变量:

text,rc = f()
text,_ = f()
_,rc = f()
或者您可以使用:

text,rc = f()
text = f()[0]
rc = f()[1]
您甚至可以使用多个:

_,_,_,x = method_returning_4_args_and_only_want_the_last()

一种常见的Python习惯用法是将
\uuu
用作伪变量:

text,rc = f()
text,_ = f()
_,rc = f()
或者您可以使用:

text,rc = f()
text = f()[0]
rc = f()[1]
您甚至可以使用多个:

_,_,_,x = method_returning_4_args_and_only_want_the_last()