说我有一个功能
def equals_to(x,y):
a + b = c
def some_function(something):
for i in something:
...
有没有办法使用c
计算的equals_to
作为此some_function
的参数
equals_to(1,2)
some_function(c)
答案 0 :(得分:3)
您需要return
函数中c
的值。
def equals_to(x,y):
c = x + y # c = x + y not a + b = c
return c # return the value of c
def some_function(something):
for i in something:
...
return
sum = equals_to(1,2) # set sum to the return value from the function
some_function(sum) # pass sum to some_function
equals_to
的函数签名也会使用参数x,y
,但在您使用的函数a,b
中,您的作业轮回错误,c
取值{ x + y
而非a + b
等于c
。