我有一塊應被打印數的代碼。但它會打印出「無」,以及我預計要打印的數字。這裏是一個應該產生,在最後一行代碼3.Python--打印結果示出「無」和期望的結果
mylist=[]
def number_replied(user):
for z in task1dict:
if user in task1dict[z]:
mylist.append(z)
def how_many_replied_to(username):
del(mylist[:])
number_replied(username)
print(len(mylist))
print(how_many_replied_to('joeclarkphd'))
這應該產生的結果,「3」的片段,只是數字,但它顯示「無」,一個換行符,「 3" 。有什麼我需要添加或更改?讓我知道你是否需要更多的代碼。
將print(len(mylist))更改爲'return len(mylist)'您的函數默認返回None,因爲您沒有return語句 –
http://stackoverflow.com/questions/34404947的重複項/我的功能 - 回報 - 無 – Prune