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

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

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

        尝试在 Python 中扩展列表时出现类型错误

        Type error when trying to extend a list in Python(尝试在 Python 中扩展列表时出现类型错误)
        • <legend id='8i2Rr'><style id='8i2Rr'><dir id='8i2Rr'><q id='8i2Rr'></q></dir></style></legend>

          <small id='8i2Rr'></small><noframes id='8i2Rr'>

            <tbody id='8i2Rr'></tbody>
          <tfoot id='8i2Rr'></tfoot>

            <bdo id='8i2Rr'></bdo><ul id='8i2Rr'></ul>

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

                1. 本文介绍了尝试在 Python 中扩展列表时出现类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要明白为什么:

                  years = range(2010,2016)
                  years.append(0)
                  

                  是可能的,返回:

                  [2010,2011,2012,2013,2014,2015,0]
                  

                  years = range(2010,2016).append(0)
                  

                  years = [0].extend(range(2010,2016))
                  

                  不工作?

                  我知道这是我收到的消息中的类型错误.但我想在这背后有更多的解释.

                  I understand that it is a type error from the message I got. But I'd like to have a bit more explanations behind that.

                  推荐答案

                  你正在存储 list.append()list.extend() 方法的结果;两者都更改列表就地并返回None.他们确实不会再次返回列表对象.

                  You are storing the result of the list.append() or list.extend() method; both alter the list in place and return None. They do not return the list object again.

                  不存储 None 结果;存储 range() 结果,then 扩展或追加.或者,使用串联:

                  Do not store the None result; store the range() result, then extend or append. Alternatively, use concatenation:

                  years = range(2010, 2016) + [0]
                  years = [0] + range(2010, 2016)
                  

                  请注意,我假设您使用的是 Python 2(否则您的第一个示例将无法正常工作).在 Python 3 中 range() 不会产生列表;您必须使用 list() 函数将其转换为一个:

                  Note that I'm assuming you are using Python 2 (your first example would not work otherwise). In Python 3 range() doesn't produce a list; you'd have to use the list() function to convert it to one:

                  years = list(range(2010, 2016)) + [0]
                  years = [0] + list(range(2010, 2016))
                  

                  这篇关于尝试在 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 数据框制作线图?)

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

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

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

                          <tbody id='Bjwra'></tbody>

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