简体   繁体   English

为什么我不能将 True 存储在 Set 中?

[英]Why can't I store True in a Set?

I have this code:我有这段代码:

mySet = {1,"2",3.0,True}
print("Set: " , mySet)

The output is output 是

Set:  {1, 3.0, '2'}

What happened to the 'True'? “真”怎么了?

Because set save unique value one time and 1 and True == 1 are same.因为set save unique value one time and 1True == 1是一样的。 For this reason, you see 1 one time.因此,您一次看到1

>>> {1,True}
{1}

>>> {0,False}
{0}

>>> {'1',True}
{'1',True}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM