[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/pythonpeixun/article/master/python/python_iterator.md [Back]  [Original]

#python

18610508486@163.com

##python

###2

1\_\_iter\_\__\_iter\_\_ return self 

2next()python3 \_\_next\__()

###python 3

```
class Reverse:
    """
    python,
    python
    https://github.com/pythonpeixun/article/blob/master/index.md
    python
    https://github.com/pythonpeixun/article/blob/master/beijing_weekend.md
    :qq:1465376564  :18610508486 
    """

    def __init__(self, data):
        self.data = data
        self.index = len(data)

    def __iter__(self):
        return self

    def __next__(self):
        if self.index == 0:
            raise StopIteration
        self.index = self.index - 1
        return self.data[self.index]

foo = Reverse(range(10))
print(foo)
#

for i in foo:
    print(i, end=",")

#9,8,7,6,5,4,3,2,1,0,

```

Web Proxy Viewer  |  New URL  |  Original Page