0
def get_name():
import random
lst = ["aa", "bbb", "ccc", "dddd", "eee", "stop"]
return random.choice(lst)
def poi(name, lst):
res = get_name()
lst.append(res)
if res !="stop":
poi(name, lst)
else:
print lst
return lst
if __name__ == '__main__':
print poi("xx", [])
poi()
方法将项目添加到通过列表,并应返回列表,直到“停止”在列表中。如果 “停” 在列表中,然后返回列表更新python列表上的转移呼叫返回无
print lst
打印['bbb', 'dddd', 'bbb', 'stop']
#1
但
`print poi("xx", [])` prints `None` #2
为什么#2
是印刷None
,而不是更新的列表?
或者例如http://stackoverflow.com/q/2599149/3001761或http://stackoverflow.com/q/15210646/3001761 – jonrsharpe