| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/Lovepython015/Python/master/Article/PythonBasis/python7/5.md | [Back] [Original] |
# #
## 1 ##
list 1 5
```python
list1 = [1,2,3,4,5]
for num1 in list1 :
print ( num1 , end = ' ' )
```
5 1 Python `reversed()`
```python
list1 = [1,2,3,4,5]
for num1 in reversed(list1) :
print ( num1 , end = ' ' )
```
** `__reversed__()` **
`__reversed__()`
```python
# -*- coding: UTF-8 -*-
class Countdown:
def __init__(self, start):
self.start = start
def __iter__(self):
# Forward iterator
n = self.start
while n > 0:
yield n
n -= 1
def __reversed__(self):
# Reverse iterator
n = 1
while n
| Web Proxy Viewer | New URL | Original Page |