以下程序来自python一书。在此代码中,计数首先设置为0,然后使用while True
。在本书中,我读到零和空字符串评估为False,而其他所有值评估为True。如果是这种情况,那么程序如何执行while循环?计数不会被计数为False,因为计数设置为0?while循环并将值解释为True或False
有人能解释一下吗?
# Finicky Counter
# Demonstrates the break and continue statements
count = 0
while True: # while count is True
count += 1
# end loop if count greater than 10
if count > 10:
break
# skip 5
if count == 5:
continue
print(count)
input("\n\nPress the enter key to exit.")
'#while count count'True' this comment is confusing。在那个特定的行中,代码只检查“True”的值,因为它是真的,它会进入'while'。 – Lafexlos