>有人有描述为什么这是给出的行为吗?
if (key in self.dict) == True:
与
if key in self.dict == True:
我的优先级顺序表告诉我这两个运算符应该从左到右计算,但由于某种原因,我实际上在我给出的第二个示例中看到了不正确的行为。 有谁知道为什么括号在这里很重要?
https://docs.python.org/3/reference/expressions.html#operator-precedence
据我了解,这两条线的评价应该完全相同。
可重现:
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> dict = {}
>>> dict[1] = 2
>>> 1 in dict
True
>>> 1 in dict == True
False
>>> (1 in dict) == True
True
>>> 1 in (dict == True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument of type 'bool' is not iterable
相关部分是比较:
比较可以任意链接,例如,x
<= z 是等价的 到 x 相关内容
- 顺序批处理vs并行批处理?
- async/await vs回调解析顺序,给定共享异步性
- Guid vs Tuple<Guid的哈希集,Guid>作为字典键:Guid的顺序应该无关紧要
- 是否可以在 VS 代码中更改 Flutter 的自动完成顺序?
- 防止VS Codium中命令序列执行的异步顺序
- 为什么不同?异步顺序运行vs并行运行
- Golang -并发vs并行vs顺序
- VS中的SQL Server数据库项目.生成过程中SQL脚本生成步骤的顺序
- Java 运算符 && vs 的求值顺序 ||
- .NET VS获胜窗体项目中的序列化顺序(设计器代码)出现问题
- VS代码:如何按照InteliJ的特定顺序对导入进行排序
- Python 顺序优先级(在 vs "==" 中)
- JSON.net vs XPATH:如何在选择令牌中保留节点顺序?
- numpy (logical_and vs '&') 语句的顺序导致不同的结果
- 更改 VS 智能感知语句完成行为顺序
- localeCompare() vs .按字母顺序排序
- Spark:repartition vs partitionBy 中列参数的顺序
- GWT并行编译vs顺序编译
- 预先计算数据vs顺序处理
- Android动画:同步vs顺序
最新更新
- 如何转换int值从csv到datetime在Spark SQL?
- 如何在同一行中添加输入和按钮
- 让加密403错误当在遗留(EOL)上安装certbot-auto时需要SNI错误
- C对文本文件中的整数进行选择排序,并将排序后的数字写入新文件
- 如何使Java Rest API在处理前半部分后返回响应,然后在返回响应后继续后半部分?
- SvelteKit未看到[id].苗条的文件
- Gitlab CI and php verstion
- ROS2-Gazebo:在立方体的一侧显示图像
- appery.模态离子1中的IO固定组件
- 一种检查is_explicit _constructible的方法
- 从电子表格自动填充谷歌文档
- 由CSS值更改触发的CSS动画
- CSS Sticky属性在本演示中不起作用
- NodeJs与xmlrpc服务器通信,并对node-xmlrpc库进行base64编码,将下载的url图像编码为base
- 在管道中使用powershell如何使用在azure devops中触发的管道运行来获取shelvesset编号.<
- 我希望在表格单元格内的左、右位置的同一行中有不同的文本
- Entity Framework ExecuteDelete没有按预期工作
- 颤振只加载某些riv (.riv)文件
- Python问题我如何循环回我的代码?
- asyncpg.exceptions.InvalidAuthorizationSpecificationError Py
- 为什么我的阅读更多按钮不工作?
- 如何得到拆分字符后的单词
- 在列表框之间移动项
- 设置 SKEmitterNode 的 'targetNode' 会导致奇怪的 'zPosition' 行为
- 我无法在斐波那契数列 python 中加强术语
- 用Jest测试使用jquery获取数据的异步函数
- c#与HTML敏捷包不能得到div类的值
- Python 中的 OOP 层次结构
- 我如何动画下拉菜单的高度使用顺风css
- 无法从字符串比较失败的字符串中删除"—"
热门标签:
javascript python java c# php android html jquery c++ css ios sql mysql arrays asp.net json python-3.x ruby-on-rails .net sql-server django objective-c excel regex ruby linux ajax iphone xml vba spring asp.net-mvc database wordpress string postgresql wpf windows xcode bash git oracle list vb.net multithreading eclipse algorithm macos powershell visual-studio image forms numpy scala function api selenium