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

    <tfoot id='V4Nqv'></tfoot>

  • <legend id='V4Nqv'><style id='V4Nqv'><dir id='V4Nqv'><q id='V4Nqv'></q></dir></style></legend>

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

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

        True 和 1 和 1.0 在 python 字典中被评估为相同

        True and 1 and 1.0 evaluated to be same in python dictionaries(True 和 1 和 1.0 在 python 字典中被评估为相同)
      1. <legend id='lLqLx'><style id='lLqLx'><dir id='lLqLx'><q id='lLqLx'></q></dir></style></legend>
          <tbody id='lLqLx'></tbody>
            <tfoot id='lLqLx'></tfoot>

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

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

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

                1. 本文介绍了True 和 1 和 1.0 在 python 字典中被评估为相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  谁能解释一下python字典的这种行为?

                  Can anyone explain this behaviour of python dictionaries?

                  d = {}
                  d[True] = 'Magic'
                  d[1] = 'Cool'
                  d[1.0] = 'Hello'
                  print(d)
                  
                  # {True: 'Hello'}
                  

                  为什么它不打印所有其他(键、值)对?

                  Why does it not print all the other (key, value) pairs?

                  为什么 True、1 和 1.0 被评估为相同?

                  Why does True, 1 and 1.0 is evaluated to be the same?

                  推荐答案

                  hash 3 项 1, 1.0, True 相同(等于 1).如果没有冲突,这就是 python 用作字典键的内容.并且由于 1 == 1.0 == True 也是 True 没有冲突.

                  the hash of the 3 items 1, 1.0, True is the same (it equals 1). that's what python uses as the key for dictionaries if there are no collisions. and as 1 == 1.0 == True is also True there are no collisions.

                  这里有更多关于python 旧实现的详细信息字典.新的实现按照这些思路做事(但保留了顺序).

                  here are more details about the old implementation of python dictionaries. the new implementation does things along those lines (but preserves the order).

                  这篇关于True 和 1 和 1.0 在 python 字典中被评估为相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                  • <bdo id='zJhFi'></bdo><ul id='zJhFi'></ul>

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

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