码:

def function1(a,b):
    return a-1,b-1
def function2(c,d):
    return c+1,d+1

print function1(function2(1,2))


错误:

Traceback (most recent call last):
  File "C:\Users\sony\Desktop\Python\scripts\twitter_get_data.py", line 6, in <module>
    print function1(function2(1,2))
TypeError: function1() takes exactly 2 arguments (1 given)
[Finished in 0.1s with exit code 1]


为什么会出现以上错误?

最佳答案

这些函数返回元组,因为return仅返回一项。您可以在返回的元组前面加星号来“解包”。语法如下所示:

print function1(*function2(1,2))

关于python - 将函数调用作为函数参数传递,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30987651/

10-11 22:35
查看更多