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

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

          <bdo id='wKe0C'></bdo><ul id='wKe0C'></ul>
      1. 为什么 python 字符串没有 __iter__ 函数?

        时间:2023-10-19

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

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

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

          • <i id='jzomA'><tr id='jzomA'><dt id='jzomA'><q id='jzomA'><span id='jzomA'><b id='jzomA'><form id='jzomA'><ins id='jzomA'></ins><ul id='jzomA'></ul><sub id='jzomA'></sub></form><legend id='jzomA'></legend><bdo id='jzomA'><pre id='jzomA'><center id='jzomA'></center></pre></bdo></b><th id='jzomA'></th></span></q></dt></tr></i><div id='jzomA'><tfoot id='jzomA'></tfoot><dl id='jzomA'><fieldset id='jzomA'></fieldset></dl></div>
            <tfoot id='jzomA'></tfoot>
                    <tbody id='jzomA'></tbody>
                  本文介绍了为什么 python 字符串没有 __iter__ 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当字符串没有 __iter__ 函数时,我们如何迭代 python 字符串?

                  How is it that we can iterate over python strings when strings don't have an __iter__ function?

                  $ python
                  Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
                  [GCC 4.4.3] on linux2
                  Type "help", "copyright", "credits" or "license" for more information.
                  >>> "asdf".__iter__
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                  AttributeError: 'str' object has no attribute '__iter__'
                  >>> it = iter("asdf")      
                  >>> it
                  <iterator object at 0xb736f5ac>
                  >>> 
                  

                  更重要的是(无论如何迭代字符串),为什么 python 字符串不遵循与其他所有内容相同的约定.特别是当 Python 文档说需要 __iter__ 函数时 http://docs.python.org/library/functions.html#iter ?

                  And more importantly (however strings are iterated over), why do python strings not follow the same convention as everything else. Particularly when the Python docs say that the __iter__ function is needed http://docs.python.org/library/functions.html#iter ?

                  推荐答案

                  来自您的链接:

                  或者它必须支持序列协议(__getitem__() 方法整数参数从 0 开始).

                  or it must support the sequence protocol (the __getitem__() method with integer arguments starting at 0).

                  In [1]: 'foo'.__getitem__(0)
                  Out[1]: 'f'
                  

                  这篇关于为什么 python 字符串没有 __iter__ 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:python的可变长度参数(*args)是否在函数调用时扩展生成器? 下一篇:如何迭代这个 n 维数据集?

                  相关文章

                    <tfoot id='ykInT'></tfoot>

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

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

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