我最近开始学习python,但无法弄清楚为什么下面的代码没有输出:
def countdown():
i = 5
while i > 0:
return i
i -= 1
print (i)
return
退出了该函数。您可能打算这样做:
def countdown():
i = 5
while i > 0:
print(i)
i -= 1
return i
然后调用函数:countdown()
输出:
5 4 3 2 1