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