<small id='IkIyE'></small><noframes id='IkIyE'>

    <i id='IkIyE'><tr id='IkIyE'><dt id='IkIyE'><q id='IkIyE'><span id='IkIyE'><b id='IkIyE'><form id='IkIyE'><ins id='IkIyE'></ins><ul id='IkIyE'></ul><sub id='IkIyE'></sub></form><legend id='IkIyE'></legend><bdo id='IkIyE'><pre id='IkIyE'><center id='IkIyE'></center></pre></bdo></b><th id='IkIyE'></th></span></q></dt></tr></i><div id='IkIyE'><tfoot id='IkIyE'></tfoot><dl id='IkIyE'><fieldset id='IkIyE'></fieldset></dl></div>
    • <bdo id='IkIyE'></bdo><ul id='IkIyE'></ul>
    <legend id='IkIyE'><style id='IkIyE'><dir id='IkIyE'><q id='IkIyE'></q></dir></style></legend>

    <tfoot id='IkIyE'></tfoot>

      Python设置1和True的interpetation

      时间:2023-07-03
    1. <tfoot id='WDxPt'></tfoot>
      <i id='WDxPt'><tr id='WDxPt'><dt id='WDxPt'><q id='WDxPt'><span id='WDxPt'><b id='WDxPt'><form id='WDxPt'><ins id='WDxPt'></ins><ul id='WDxPt'></ul><sub id='WDxPt'></sub></form><legend id='WDxPt'></legend><bdo id='WDxPt'><pre id='WDxPt'><center id='WDxPt'></center></pre></bdo></b><th id='WDxPt'></th></span></q></dt></tr></i><div id='WDxPt'><tfoot id='WDxPt'></tfoot><dl id='WDxPt'><fieldset id='WDxPt'></fieldset></dl></div>

        <legend id='WDxPt'><style id='WDxPt'><dir id='WDxPt'><q id='WDxPt'></q></dir></style></legend>

        <small id='WDxPt'></small><noframes id='WDxPt'>

            <bdo id='WDxPt'></bdo><ul id='WDxPt'></ul>

                <tbody id='WDxPt'></tbody>
                本文介绍了Python设置1和True的interpetation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在 IPython 3 交互式外壳中:

                In IPython 3 interactive shell:

                In [53]: set2 = {1, 2, True, "hello"}
                
                In [54]: len(set2)
                Out[54]: 3
                
                In [55]: set2
                Out[55]: {'hello', True, 2}
                

                这是因为 1 和 True 得到相同的交互作用,所以假设 set 消除了重复项,那么只有其中一个 (True) 可以保留?我们如何才能两者兼得?

                Is that because 1 and True get the same interpetation so given that set eliminates duplicates, only one of them (True) gets to stay? How can we keep both?

                推荐答案

                集合是 hashables.即使语句 1 is True 是 False,语句 1 == True 也是 True.因此,它们具有相同的哈希值,不能单独存在于一个集合中,并且你不能将它们都放在一个集合中

                A set is a collection of hashables. Even though the statement 1 is True is False, the statement 1 == True is True. Because of that, they have the same hash value and cannot exist separately in a set, and you cannot keep them both in a set

                EDIT 明确地说,正如 jme 指出的那样,这是因为两件事都是真实的——它们是相等的(每个 __eq__)并且它们具有相同的 哈希值(每个 __hash__).

                EDIT To make it explicit, as jme pointed out, it is because BOTH things are true - they are equal (per __eq__) AND they have the same hash value (per __hash__).

                在一个完美的世界中,相等的对象也将具有相同的哈希值,幸好这对于内置类型是正确的.

                In a perfect world, equal objects would also have the same hash value, and thankfully this is true for built-in types.

                这篇关于Python设置1和True的interpetation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:从python中的元组或集合列表中查找不相交的集合 下一篇:查找列表中不常见的元素

                相关文章

                  <legend id='HToPR'><style id='HToPR'><dir id='HToPR'><q id='HToPR'></q></dir></style></legend>

                  1. <tfoot id='HToPR'></tfoot>

                    • <bdo id='HToPR'></bdo><ul id='HToPR'></ul>
                  2. <small id='HToPR'></small><noframes id='HToPR'>

                    <i id='HToPR'><tr id='HToPR'><dt id='HToPR'><q id='HToPR'><span id='HToPR'><b id='HToPR'><form id='HToPR'><ins id='HToPR'></ins><ul id='HToPR'></ul><sub id='HToPR'></sub></form><legend id='HToPR'></legend><bdo id='HToPR'><pre id='HToPR'><center id='HToPR'></center></pre></bdo></b><th id='HToPR'></th></span></q></dt></tr></i><div id='HToPR'><tfoot id='HToPR'></tfoot><dl id='HToPR'><fieldset id='HToPR'></fieldset></dl></div>