Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.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_Algorithm_Function - Fatal编程技术网

将函数作为参数传递给其他函数时的Python执行流

将函数作为参数传递给其他函数时的Python执行流,python,algorithm,function,Python,Algorithm,Function,下面是“将函数作为参数传递给其他函数”的示例。我一直在努力理解这些语句的执行流程 1 def plus_one(number): 2 print(f" First: {number + 1}") 3 return number + 1 4 5 def function_call(function): 6 number_to_add = 5 7 print(f" Second: {function(number

下面是“将函数作为参数传递给其他函数”的示例。我一直在努力理解这些语句的执行流程

 1  def plus_one(number):
 2      print(f" First: {number + 1}")
 3      return number + 1
 4
 5  def function_call(function):
 6      number_to_add = 5
 7      print(f" Second: {function(number_to_add)}")
 8      return function(number_to_add)
 9
10  function_call(plus_one)
上述报表的输出:

第一:6

第二:6

第一:6

首先调用哪个函数-“函数调用”或“加一”

根据我的理解,首先调用函数_call,参数为plus _onefn

但是,根据打印输出,首先调用一个函数。请解释此类函数调用背后的逻辑,如果可能,请与类似示例共享任何好的文档。

print(f" Second: {function(number_to_add)}")

它调用
函数
,以获取要打印的返回值<首先调用code>function\u call,但是在
function\u call
中的
print
之前调用
plus\u one
,在第5行和第6行之间添加一个print语句,看看这是怎么回事。”……但是对plus\u one的调用是在print in function\u调用之前进行的。”哪个语句调用plus\u one或“function”?我在回答中显示的行调用了
plus\u one
,它已作为参数
function
传入。