下面的循环是一个有条件的while,我只是想知道它怎么会变成一个无限循环。
count = 0
while count!=12 or count!=6:
count = count + 1
print(count)
请您参考如下方法:
将 or 更改为 and,如所写,您的条件始终为 True。
while count != 12 and count != 6:
count 不能同时为 12 和 6,因此其中一个表达式将始终为 True。
这个表达式可以用 De Morgan's laws 来解释
在 Python 中这将是
not (p or q) == (not p) and (not q)
