[英]Python: function arguments and return values
說我有一個功能
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)
您需要從函數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
。
強烈建議: http : //docs.python.org/2/tutorial/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.