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

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

      <tfoot id='OG3Ub'></tfoot>
    1. Python list += iterable 的行为是否记录在任何地方?

      Is the behaviour of Python#39;s list += iterable documented anywhere?(Python list += iterable 的行为是否记录在任何地方?)
        <bdo id='5qFXf'></bdo><ul id='5qFXf'></ul>
          <tbody id='5qFXf'></tbody>
      • <small id='5qFXf'></small><noframes id='5qFXf'>

          • <legend id='5qFXf'><style id='5qFXf'><dir id='5qFXf'><q id='5qFXf'></q></dir></style></legend>

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

              1. 本文介绍了Python list += iterable 的行为是否记录在任何地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在 Python 中,list += x 似乎适用于任何可迭代的 x:

                在[6]中:l = []在 [7] 中:l += [1]在 [8] 中:l += (2, 3)在 [9] 中: l += xrange(5)在[10]中:l输出[10]:[1、2、3、0、1、2、3、4]

                这种行为是否记录在任何地方?

                为了与 list + x 进行对比,后者仅在 x 也是 list 时才有效.这在 文档.

                解决方案

                来自 Guido van Rossum:p><块引用>

                它的工作方式与 .extend() 相同,只是它也返回 self.一世找不到解释这一点的文档.:-(

                这里是取自 listobject.c:

                list_inplace_concat(PyListObject *self, PyObject *other){PyObject *结果;结果 = 列表扩展(自我,其他);如果(结果 == NULL)返回结果;Py_DECREF(结果);Py_INCREF(自我);返回(PyObject *)自我;}

                我已提交错误报告以修复文档:http://bugs.python.org/issue16701

                It would appear that in Python, list += x works for any iterable x:

                In [6]: l = []
                
                In [7]: l += [1]
                
                In [8]: l += (2, 3)
                
                In [9]: l += xrange(5)
                
                In [10]: l
                Out[10]: [1, 2, 3, 0, 1, 2, 3, 4]
                

                Is this behaviour documented anywhere?

                To contrast this with list + x, the latter only works if x is also a list. This is spelled out in the documentation.

                解决方案

                From Guido van Rossum:

                It works the same way as .extend() except that it also returns self. I can't find docs explaining this. :-(

                Here is the relevant source code taken from listobject.c:

                list_inplace_concat(PyListObject *self, PyObject *other)
                {
                     PyObject *result;
                
                     result = listextend(self, other);
                     if (result == NULL)
                         return result;
                     Py_DECREF(result);
                     Py_INCREF(self);
                     return (PyObject *)self;
                }
                

                I've raised a bug report to have the documentation fixed: http://bugs.python.org/issue16701

                这篇关于Python list += iterable 的行为是否记录在任何地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                • <small id='XrMrW'></small><noframes id='XrMrW'>

                • <tfoot id='XrMrW'></tfoot>
                    <tbody id='XrMrW'></tbody>

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

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

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