我开始学习python。 这有什么不对? 为什么我没有输出
谢谢,抱歉我的英语不好
def countdown():
i=5
while i > 0:
return i
i -= 1
print (i)
答案 0 :(得分:1)
正如@alfasin在评论中所说,你在函数执行任何操作之前使用return
来避免使用该函数。
你可能打算这样做:
def countdown():
i = 5
while i > 0:
print(i)
i -= 1
return i
然后调用函数:
countdown()
输出:
5
4
3
2
1