为什么会出现以下错误?最后一个 print
语句不应该是 while
循环的一部分。
>>> while n>= 0:
... n = n-1
... print(n)
... print ("TO A!!")
File "<stdin>", line 4
print ("TO A!!")
^
SyntaxError: invalid syntax
最佳答案
您需要在 while
循环后按 enter 退出循环
>>> n = 3
>>> while n>=0:
... n = n-1
... print (n)
... # Press enter here
2
1
0
-1
>>> print ("To A!!")
To A!!
注意:- ...
意味着您仍在 while
block 中
关于Python缩进之谜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28525307/