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

<legend id='tjNf4'><style id='tjNf4'><dir id='tjNf4'><q id='tjNf4'></q></dir></style></legend>
    1. <small id='tjNf4'></small><noframes id='tjNf4'>

      <tfoot id='tjNf4'></tfoot>

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

        只需要索引:枚举还是(x)范围?

        时间:2023-11-08
      1. <legend id='4GzMz'><style id='4GzMz'><dir id='4GzMz'><q id='4GzMz'></q></dir></style></legend>

            • <small id='4GzMz'></small><noframes id='4GzMz'>

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

                  本文介绍了只需要索引:枚举还是(x)范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我只想在循环中使用索引,我应该更好地使用 range/xrange 函数和 len()

                  If I want to use only the index within a loop, should I better use the range/xrange function in combination with len()

                  a = [1,2,3]
                  for i in xrange(len(a)):
                      print i 
                  

                  枚举?即使我根本不会使用 p ?

                  or enumerate? Even if I won't use p at all?

                  for i,p in enumerate(a):
                      print i    
                  

                  推荐答案

                  我会使用 enumerate,因为它更通用 - 例如,它适用于可迭代对象和序列,以及仅返回引用的开销到一个对象并不是什么大不了的事 - 虽然 xrange(len(something)) 虽然(对我来说)更容易阅读你的意图 - 会破坏不支持 len 的对象...

                  I would use enumerate as it's more generic - eg it will work on iterables and sequences, and the overhead for just returning a reference to an object isn't that big a deal - while xrange(len(something)) although (to me) more easily readable as your intent - will break on objects with no support for len...

                  这篇关于只需要索引:枚举还是(x)范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:无限范围() 下一篇:跳过python中范围函数中的值

                  相关文章

                      <bdo id='eE669'></bdo><ul id='eE669'></ul>
                    <tfoot id='eE669'></tfoot>

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

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

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