0

说我有一个功能

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)
4

1 回答 1

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 + ynot a + bequals的值c

强烈推荐:http ://docs.python.org/2/tutorial/

于 2012-12-07T09:07:22.373 回答