<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 字典中被评估为相同

        时间:2023-09-01
      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 字典中被评估为相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:python 如何“否定"value : 如果为真则返回假,如果为假则返回真 下一篇:Python“和"带整数的运算符

                  相关文章

                  • <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>
                  1. <legend id='zJhFi'><style id='zJhFi'><dir id='zJhFi'><q id='zJhFi'></q></dir></style></legend><tfoot id='zJhFi'></tfoot>