Python:函数参数和返回值
假设我有一个函数Python:函数参数和返回值,python,function,Python,Function,假设我有一个函数 def equals_to(x,y): a + b = c def some_function(something): for i in something: ... 有没有一种方法可以使用由equals_to计算的c作为某个函数的参数 equals_to(1,2) some_function(c) 您需要从函数中返回c的值 def equals_to(x,y): c = x + y # c = x + y not a + b = c
def equals_to(x,y):
a + b = c
def some_function(something):
for i in something:
...
有没有一种方法可以使用由equals_to
计算的c
作为某个函数的参数
equals_to(1,2)
some_function(c)
您需要从函数中返回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
equalsc
强烈建议:您需要从函数返回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
equalsc
强烈推荐:什么是c
,a
和b
?他们是从哪里来的?我对你想要实现的目标感到非常困惑equals_to
不编译,它看起来是要返回一个整数,这在blah
语句中对x不起作用。`def equals_to(x,y)`应该说def equals_to(a,b)
我在键入示例时犯了一个错误。而且a+b=c
应该是c=a+b
什么是c
,a
和b
?他们是从哪里来的?我对你想要实现的目标感到非常困惑equals_to
不编译,它看起来是要返回一个整数,这在blah
语句中对x不起作用。`def equals_to(x,y)`应该说def equals_to(a,b)
我在键入示例时犯了一个错误。而且a+b=c
应该是c=a+b