代码:
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]
为什么出现上述错误?
答案 0 :(得分:5)
函数返回元组,因为return
只返回一个项目。你可以解开&#34;解压缩&#34;通过在星号前添加元组返回的元组。语法如下所示:
print function1(*function2(1,2))