因为在Python
1 == True(和
hash(1) == hash(True))中,您的集合中已经有1个了。
想象一下这个例子:
example1 = {0, False, None}example2 = {1, True}print(example1)print(example2)将输出:
{0, None}{1}第一组有
0和
None,因为
0 == False但
0 != None。对于第二组
1 == True,
True则不会添加到该组中。

因为在Python
1 == True(和
hash(1) == hash(True))中,您的集合中已经有1个了。
想象一下这个例子:
example1 = {0, False, None}example2 = {1, True}print(example1)print(example2)将输出:
{0, None}{1}第一组有
0和
None,因为
0 == False但
0 != None。对于第二组
1 == True,
True则不会添加到该组中。