python - Python while 不循环
问题描述
我是 Python 新手,无法理解以下代码:
i = 0
j = 0
while not(i < 3 or j == 5):
i = i + 1
j = j + 1
print(i)
返回 0,即使 j == 5 的逆(非)返回 true
解决方案
not(i < 3 or j == 5)
等价于(通过De Morgan 的对偶性):
not(i < 3) and not(j ==5)
进一步简化为:
(i >= 3) and (j != 5)
所以既然i = j = 0
这个条件不满足。
推荐阅读
- php - 如何在相等的部分中循环数组和块?
- c# - 在 C# 中格式化十进制数
- python - 格式化 AWS lambda 请求的 Python 错误
- hyperledger-fabric - 无法使用 Hyperledger Fabric 节点 SDK 让对等方加入频道
- python - Keras 加载模型
- c# - 在 Python 中模仿 C# 类
- scripting - 用于修改身份验证数据条目的 wsadmin 脚本/命令参数
- python - TypeError:“int”对象不可下标 - 尝试创建 csv 文件时
- typescript - 使用 Typescript 构建纯 Vue 组件的最佳方法是什么
- python - BeautifulSoup 从 Web 获取表格时返回 No Data Recorded