<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 范围

        时间:2023-11-08
      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 范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python:从间隔映射到值 下一篇:使用 range() 以相反的顺序打印列表?

                  相关文章

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

                    1. <tfoot id='W65Fq'></tfoot>
                    2. <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>

                    3. <legend id='W65Fq'><style id='W65Fq'><dir id='W65Fq'><q id='W65Fq'></q></dir></style></legend>
                        <bdo id='W65Fq'></bdo><ul id='W65Fq'></ul>