Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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 - Fatal编程技术网

Python输出参数?

Python输出参数?,python,Python,是否可以这样做: def foo(bar, success) success = True # ... >>> success = False >>> foo(bar1, success) >>> success True Python是否有out参数,或者是否有一种简单的方法来模拟它们?(除了干扰父级堆栈帧之外。)您有多个返回值 def foo(bar) return 1, 2, True x, y, succ

是否可以这样做:

def foo(bar, success)
    success = True
    # ...

>>> success = False
>>> foo(bar1, success)
>>> success
True

Python是否有out参数,或者是否有一种简单的方法来模拟它们?(除了干扰父级堆栈帧之外。)

您有多个返回值

def foo(bar)
    return 1, 2, True

x, y, success = foo(bar1)

您有多个返回值

def foo(bar)
    return 1, 2, True

x, y, success = foo(bar1)

是的,将它们作为参数传递到dict中。我想它在python官方教程的某个地方。

是的,将它们作为参数传递到dict中。我认为它在主要的python官方教程中的某个地方。

在python中,不能从函数内部更新不可变的类型(如示例中的布尔值、int、字符串或元组等)。时期因此,您的选择如前面的答案所示:

  • 将不可变类型包装为可变类型(如列表、数组或对象)
  • 使用多个返回值

  • 在python中,不能从函数内部更新不可变类型(如示例中的布尔值、int、字符串或元组等)。时期因此,您的选择如前面的答案所示:

  • 将不可变类型包装为可变类型(如列表、数组或对象)
  • 使用多个返回值