0
choice = None
while choice != 0:
    print("Hello")

    choice = 0

In this circumstance why does the string "Hello" only print once? Shouldn't choice reset to None after the ending of the while loop, thus resulting in an infinite print("Hello")?

4

1 回答 1

4

要修复它,请尝试执行以下操作:

choice = None
while choice != 0:
    print("Hello")

choice = 0

由于您缩进了最后一行,Python 认为它是您循环的一部分。

于 2013-09-22T19:20:26.287 回答