为什么当 x
时退出下面的 while 循环达到0
?
x = 1
while x:
print(x)
x -= 1
它只打印 1
。 while 语句不应该是这样的: while x "is something":
不仅仅是while x:
?
最佳答案
因为 bool(0) => False
和 bool(x) for x!=0 => True
,所以这就像是说 while x! =0
或 while x>0
在您的情况下。
关于Python "while x:"语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46045023/