<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] # 對象迭代 ~~~ for temp in xxx_obj: pass ~~~ 1. 判斷xx_obj是否是可以迭代 2. 調用iter函數,得到xx_obj對象的`__iter__`方法的返回值 3. `__iter__`方法的返回值是一個迭代器 # 判斷是否可迭代和迭代器 ~~~ from collections import Iterable from collections import Iterator class Classmate(object): def __init__(self): self.name = list() def add(self, name): self.name.append(name) def __iter__(self): return ClassIterator() class ClassIterator(object): def __iter__(self): pass def __next__(self): pass classmate = Classmate() classmate.add('老王') classmate.add('王二') classmate.add('張三') print('判斷classmate是否是可以迭代的對象:', isinstance(classmate, Iterable)) classmate_iterator = iter(classmate) print('判斷classmate_iterator是否是迭代器:', isinstance(classmate_iterator, Iterator)) ~~~ # 完善迭代器 ~~~ from collections import Iterable from collections import Iterator class Classmate(object): def __init__(self): self.names = list() self.current_num = 0 def add(self, name): self.names.append(name) def __iter__(self): """如果想要一個對象成為一個可迭代的對象,即可以使用for,那么必須實現__iter__方法""" return self def __next__(self): if self.current_num < len(self.names): ret = self.names[self.current_num] self.current_num += 1 return ret else: raise StopIteration classmate = Classmate() classmate.add('老王') classmate.add('王二') classmate.add('張三') for name in classmate: print(name) ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看