【发布时间】:2015-03-11 18:32:45
【问题描述】:
我不知道以前是否有人问过这个问题,但我去。
while 循环接受一个布尔值,例如 while a
n = 10000
count = 0
while n:
count = count + 1
n = n / 10
n=int(n)
print (count)
这段代码将执行 while 循环,但是为什么,我知道我可以使用 1 来代替 True,但在这里它就像“while 10000”,并且 10000 != True,那么它是如何工作的?
【问题讨论】:
-
试试
bool(10000)看看魔法 -
除 0 以外的所有整数/浮点数都被解释为
True。
标签: python loops while-loop int