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

<tfoot id='LkYpV'></tfoot>
    1. <legend id='LkYpV'><style id='LkYpV'><dir id='LkYpV'><q id='LkYpV'></q></dir></style></legend>

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

        • <bdo id='LkYpV'></bdo><ul id='LkYpV'></ul>

        Python - 直接扩展列表会导致无,为什么?

        Python - Extending a list directly results in None, why?(Python - 直接扩展列表会导致无,为什么?)

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

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

                  本文介绍了Python - 直接扩展列表会导致无,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  x=[1,2,3]
                  x.extend('a')
                  

                  输出:

                  x is [1,2,3,'a']
                  

                  但是当我执行以下操作时:

                  But when I do the following:

                  [1,2,3].extend('a')
                  

                  输出:

                  None
                  

                  为什么 extend 对列表引用起作用,但对列表不起作用?

                  Why does extend work on a list reference, but not on a list?

                  我发现这个是因为我试图将 listB 附加到 listA,同时尝试将 listC 扩展到 listB.

                  I found this because I was trying to append a listB to a listA while trying to extend listC to listB.

                  listA.append([listB[15:18].extend(listC[3:12])])
                  

                  假设列表不能直接附加/扩展.解决此问题的最流行的表单解决方法是什么?

                  Supposing lists cannot be directly appended / extending. What is the most popular work around form for resolving this issue?

                  推荐答案

                  list.extend 就地修改列表并且不返回任何内容,从而导致None.在第二种情况下,它是一个正在扩展的临时列表,在该行之后立即消失,而在第一种情况下,它可以通过 x 引用.

                  list.extend modifies the list in place and returns nothing, thus resulting in None. In the second case, it's a temporary list that is being extended which disappears immediately after that line, while in the first case it can be referenced via x.

                  在尝试将 listC 扩展到 listB 时将 listB 附加到 listA.

                  to append a listB to a listA while trying to extend listC to listB.

                  您可能想试试这个,而不是使用 extend:

                  Instead of using extend, you might want to try this:

                  listA.append(listB[15:18] + listC[3:12])
                  

                  如果您想实际修改 listBlistC,则使用 extend 以多行简单的方式进行.

                  Or do it in multiple simple lines with extend if you want to actually modify listB or listC.

                  这篇关于Python - 直接扩展列表会导致无,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

                      <legend id='Rx5uQ'><style id='Rx5uQ'><dir id='Rx5uQ'><q id='Rx5uQ'></q></dir></style></legend>

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

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

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

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