0
说我有一个功能的Python:函数参数和返回值
def equals_to(x,y):
a + b = c
def some_function(something):
for i in something:
...
有没有办法使用,是由equals_to
计算为参数some_function
这样
equals_to(1,2)
some_function(c)
说我有一个功能的Python:函数参数和返回值
def equals_to(x,y):
a + b = c
def some_function(something):
for i in something:
...
有没有办法使用,是由equals_to
计算为参数some_function
这样
equals_to(1,2)
some_function(c)
您需要c
方式到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
。
什么是'c','a'和'b'?他们从哪里来? – alexvassel
我很困惑你想要完成什么。 'equals_to'不能编译,它看起来像是返回一个整数,这在'for x in blah'语句中不起作用。 – Dunes
'def equals_to(x,y)'应该说'def equals_to(a,b)'在输入例子时我犯了一个错误。 “a + b = c”应该是'c = a + b' – Keenan