相关疑难解决方法(0)

为什么在python 0,0 ==(0,0)等于(0,False)

在Python中(我只使用Python 3.6进行了检查,但我相信它应该适用于许多以前的版本):

(0, 0) == 0, 0   # results in a two element tuple: (False, 0)
0, 0 == (0, 0)   # results in a two element tuple: (0, False)
(0, 0) == (0, 0) # results in a boolean True
Run Code Online (Sandbox Code Playgroud)

但:

a = 0, 0
b = (0, 0)
a == b # results in a boolean True
Run Code Online (Sandbox Code Playgroud)

为什么两种方法的结果不同?相等运算符是否以不同方式处理元组?

python tuples operator-precedence

116
推荐指数
5
解决办法
8173
查看次数

标签 统计

operator-precedence ×1

python ×1

tuples ×1