gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:31:20 25 4
gpt4 key购买 nike

我有这个代码:

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

输出为

Set:  {1, 3.0, '2'}

“真实”发生了什么?

最佳答案

因为set保存一次unique值,并且1True == 1是相同的。因此,您会看到 1 一次。

>>> {1,True}
{1}

>>> {0,False}
{0}

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

关于python - 为什么我不能将 True 存储在 Set 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69407136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com