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

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

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

        <tfoot id='UkZMz'></tfoot>

        Python 3 范围与 Python 2 范围

        Python 3 range Vs Python 2 range(Python 3 范围与 Python 2 范围)
      1. <small id='fJWyG'></small><noframes id='fJWyG'>

          <tfoot id='fJWyG'></tfoot>

                <tbody id='fJWyG'></tbody>
              • <bdo id='fJWyG'></bdo><ul id='fJWyG'></ul>
                <i id='fJWyG'><tr id='fJWyG'><dt id='fJWyG'><q id='fJWyG'><span id='fJWyG'><b id='fJWyG'><form id='fJWyG'><ins id='fJWyG'></ins><ul id='fJWyG'></ul><sub id='fJWyG'></sub></form><legend id='fJWyG'></legend><bdo id='fJWyG'><pre id='fJWyG'><center id='fJWyG'></center></pre></bdo></b><th id='fJWyG'></th></span></q></dt></tr></i><div id='fJWyG'><tfoot id='fJWyG'></tfoot><dl id='fJWyG'><fieldset id='fJWyG'></fieldset></dl></div>
                <legend id='fJWyG'><style id='fJWyG'><dir id='fJWyG'><q id='fJWyG'></q></dir></style></legend>
                1. 本文介绍了Python 3 范围与 Python 2 范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我最近开始学习python 3.
                  python 2 中,range() 函数可用于分配列表元素:

                  I recently started learning python 3.
                  In python 2 the range() function can be used to assign list elements:

                  >>> A = []
                  >>> A = range(0,6)
                  >>> print A
                  [0, 1, 2, 3, 4, 5]
                  

                  但在 python 3 中,range() 函数输出如下:

                  But in python 3 the range() function outputs this:

                  >>> A = []
                  >>> A = range(0,6)
                  >>> print(A)
                  range(0, 6)
                  

                  为什么会这样?
                  为什么python会做这个改变?
                  是福还是祸?

                  Why is this happening?
                  Why did python do this change?
                  Is it a boon or a bane?

                  推荐答案

                  Python 3python 2 的很多地方使用 迭代器使用 lists.docs 给出了详细的解释,包括更改为 range.

                  Python 3 uses iterators for a lot of things where python 2 used lists.The docs give a detailed explanation including the change to range.

                  优点是如果您使用大范围迭代器或映射,Python 3 不需要分配内存.例如

                  The advantage is that Python 3 doesn't need to allocate the memory if you're using a large range iterator or mapping. For example

                  for i in range(1000000000): print(i)
                  

                  在 python 3 中需要更少的内存.如果您确实希望 Python 一次将列表全部展开,您可以

                  requires a lot less memory in python 3. If you do happen to want Python to expand out the list all at once you can

                  list_of_range = list(range(10))
                  

                  这篇关于Python 3 范围与 Python 2 范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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中的另一个文件中查找一个文本文件的条目)

                  1. <small id='W65Fq'></small><noframes id='W65Fq'>

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

                        • <legend id='W65Fq'><style id='W65Fq'><dir id='W65Fq'><q id='W65Fq'></q></dir></style></legend>
                            <tbody id='W65Fq'></tbody>
                            <bdo id='W65Fq'></bdo><ul id='W65Fq'></ul>