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

        <tfoot id='TSazj'></tfoot>
      1. 列表 += 元组与列表 = 列表 + 元组

        List += Tuple vs List = List + Tuple(列表 += 元组与列表 = 列表 + 元组)

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

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

                <tbody id='HNgI9'></tbody>

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

                  本文介绍了列表 += 元组与列表 = 列表 + 元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有这些任务:

                  points = []
                  point = (1, 2)
                  

                  我怎么会这样做:

                  points += point
                  

                  它工作得很好,并且给了我点 = [1, 2].但是,如果我这样做:

                  It works completely fine, and gives me points = [1, 2]. However, If I do something like:

                  points = points + point
                  

                  它给了我一个 TypeError: can only concatenate list (not "tuple") to list.不过,这些陈述不是一回事吗?

                  It gives me a TypeError: can only concatenate list (not "tuple") to list. Aren't these statements the same thing, though?

                  推荐答案

                  不同的是,list +=等价于list.extend(),取任何可迭代并扩展列表,它作为元组工作是可迭代的.(并就地扩展列表).

                  The difference, is that list += is equivalent to list.extend(), which takes any iterable and extends the list, it works as a tuple is an iterable. (And extends the list in-place).

                  另一方面,第二个将一个新列表分配给 points,并尝试将一个列表连接到一个元组,但由于不清楚预期结果是什么(列表或元组?).

                  On the other hand, the second assigns a new list to points, and attempts to concatenate a list to a tuple, which isn't done as it's unclear what the expected results is (list or tuple?).

                  这篇关于列表 += 元组与列表 = 列表 + 元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 与否?)
                  <legend id='ZkN2O'><style id='ZkN2O'><dir id='ZkN2O'><q id='ZkN2O'></q></dir></style></legend>
                  <i id='ZkN2O'><tr id='ZkN2O'><dt id='ZkN2O'><q id='ZkN2O'><span id='ZkN2O'><b id='ZkN2O'><form id='ZkN2O'><ins id='ZkN2O'></ins><ul id='ZkN2O'></ul><sub id='ZkN2O'></sub></form><legend id='ZkN2O'></legend><bdo id='ZkN2O'><pre id='ZkN2O'><center id='ZkN2O'></center></pre></bdo></b><th id='ZkN2O'></th></span></q></dt></tr></i><div id='ZkN2O'><tfoot id='ZkN2O'></tfoot><dl id='ZkN2O'><fieldset id='ZkN2O'></fieldset></dl></div>

                        <tbody id='ZkN2O'></tbody>
                      <tfoot id='ZkN2O'></tfoot>

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

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