1. <legend id='4Fbjx'><style id='4Fbjx'><dir id='4Fbjx'><q id='4Fbjx'></q></dir></style></legend>

        <bdo id='4Fbjx'></bdo><ul id='4Fbjx'></ul>
      <tfoot id='4Fbjx'></tfoot>

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

        为什么 append() 在 Python 中总是返回 None?

        Why does append() always return None in Python?(为什么 append() 在 Python 中总是返回 None?)

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

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

        • <tfoot id='kczIJ'></tfoot>

              <tbody id='kczIJ'></tbody>

                <bdo id='kczIJ'></bdo><ul id='kczIJ'></ul>
                <i id='kczIJ'><tr id='kczIJ'><dt id='kczIJ'><q id='kczIJ'><span id='kczIJ'><b id='kczIJ'><form id='kczIJ'><ins id='kczIJ'></ins><ul id='kczIJ'></ul><sub id='kczIJ'></sub></form><legend id='kczIJ'></legend><bdo id='kczIJ'><pre id='kczIJ'><center id='kczIJ'></center></pre></bdo></b><th id='kczIJ'></th></span></q></dt></tr></i><div id='kczIJ'><tfoot id='kczIJ'></tfoot><dl id='kczIJ'><fieldset id='kczIJ'></fieldset></dl></div>
                  本文介绍了为什么 append() 在 Python 中总是返回 None?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  list = [1, 2, 3]
                  print(list.append(4))   ## WRONG, print does not work, append() returns None
                  
                  ## RIGHT:
                  list.append(4)
                  print(list)  ## [1, 2, 3, 4]
                  

                  我正在学习 Python,我不确定这个问题是否特定于语言以及 append 在 Python 中是如何实现的.

                  I'm learning Python and I'm not sure if this problem is specific to the language and how append is implemented in Python.

                  推荐答案

                  append 是一个变异(破坏性)操作(它修改列表而不是返回一个新列表).进行 append 的非破坏性等效的惯用方法是

                  append is a mutating (destructive) operation (it modifies the list in place instead of of returning a new list). The idiomatic way to do the non-destructive equivalent of append would be

                  l = [1,2,3]
                  print l + [4] # [1,2,3,4]
                  print l # [1,2,3]
                  

                  回答你的问题,我的猜测是如果append返回新修改的列表,用户可能会认为它是非破坏性的,即他们可能会编写类似的代码

                  to answer your question, my guess is that if append returned the newly modified list, users might think that it was non-destructive, ie they might write code like

                  m = l.append("a")
                  n = l.append("b")
                  

                  并期望 n[1,2,3,"b"]

                  这篇关于为什么 append() 在 Python 中总是返回 None?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 数据框制作线图?)

                    <tbody id='mp8Tr'></tbody>

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

                        <tfoot id='mp8Tr'></tfoot>

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

                      1. <legend id='mp8Tr'><style id='mp8Tr'><dir id='mp8Tr'><q id='mp8Tr'></q></dir></style></legend>
                            <bdo id='mp8Tr'></bdo><ul id='mp8Tr'></ul>