Else clause on Python while statement

前端 未结 12 2165
悲&欢浪女
悲&欢浪女 2020-11-22 08:24

I\'ve noticed the following code is legal in Python. My question is why? Is there a specific reason?

n = 5
while n != 0:
    print n
    n -= 1
else:
    pri         


        
12条回答
  •  情深已故
    2020-11-22 09:13

    It is useful for social interaction.

    while (Date != "January 1st"):
        time.sleep(1)
    else:
        print("Happy new year!")
    

提交回复
热议问题