<legend id='hErPP'><style id='hErPP'><dir id='hErPP'><q id='hErPP'></q></dir></style></legend><tfoot id='hErPP'></tfoot>

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

    <bdo id='hErPP'></bdo><ul id='hErPP'></ul>
      <i id='hErPP'><tr id='hErPP'><dt id='hErPP'><q id='hErPP'><span id='hErPP'><b id='hErPP'><form id='hErPP'><ins id='hErPP'></ins><ul id='hErPP'></ul><sub id='hErPP'></sub></form><legend id='hErPP'></legend><bdo id='hErPP'><pre id='hErPP'><center id='hErPP'></center></pre></bdo></b><th id='hErPP'></th></span></q></dt></tr></i><div id='hErPP'><tfoot id='hErPP'></tfoot><dl id='hErPP'><fieldset id='hErPP'></fieldset></dl></div>
      1. 将数字 1 添加到集合中没有效果

        Adding the number 1 to a set has no effect(将数字 1 添加到集合中没有效果)
        <tfoot id='PWVeQ'></tfoot><legend id='PWVeQ'><style id='PWVeQ'><dir id='PWVeQ'><q id='PWVeQ'></q></dir></style></legend>
          <bdo id='PWVeQ'></bdo><ul id='PWVeQ'></ul>

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

              • <small id='PWVeQ'></small><noframes id='PWVeQ'>

                1. 本文介绍了将数字 1 添加到集合中没有效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我无法将整数 1 添加到现有集合中.在交互式外壳中,这就是我正在做的事情:

                  I cannot add the integer number 1 to an existing set. In an interactive shell, this is what I am doing:

                  >>> st = {'a', True, 'Vanilla'}
                  >>> st
                  {'a', True, 'Vanilla'}
                  >>> st.add(1)
                  >>> st
                  {'a', True, 'Vanilla'}   # Here's the problem; there's no 1, but anything else works
                  >>> st.add(2)
                  >>> st
                  {'a', True, 'Vanilla', 2}
                  

                  这个问题是两个月前发布的,但我认为它被误解了.我正在使用 Python 3.2.3.

                  This question was posted two months ago, but I believe it was misunderstood. I am using Python 3.2.3.

                  推荐答案

                  >>> 1 == True
                  True
                  

                  我相信你的问题是 1True 是相同的值,所以 1 是已经在集合中".

                  I believe your problem is that 1 and True are the same value, so 1 is "already in the set".

                  >>> st
                  {'a', True, 'Vanilla'}
                  >>> 1 in st
                  True
                  

                  在数学运算中,True 本身被视为 1:

                  In mathematical operations True is itself treated as 1:

                  >>> 5 + True
                  6
                  >>> True * 2
                  2
                  >>> 3. / (True + True)
                  1.5
                  

                  虽然 True 是 bool 而 1 是 int:

                  Though True is a bool and 1 is an int:

                  >>> type(True)
                  <class 'bool'>
                  >>> type(1)
                  <class 'int'>
                  

                  因为 1 in st 返回 True,我认为您应该没有任何问题.这是一个非常奇怪的结果.如果您有兴趣进一步阅读,@Lattyware 指向 PEP 285深入解释了这个问题.

                  Because 1 in st returns True, I think you shouldn't have any problems with it. It is a very strange result though. If you're interested in further reading, @Lattyware points to PEP 285 which explains this issue in depth.

                  这篇关于将数字 1 添加到集合中没有效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)

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

                    1. <small id='T7wav'></small><noframes id='T7wav'>

                        <tbody id='T7wav'></tbody>
                        <bdo id='T7wav'></bdo><ul id='T7wav'></ul>
                          <tfoot id='T7wav'></tfoot>