1.循环（loop）

2.迭代（Iterate）

3.递归（recursion）

4.遍历（traversal）

逐个访问

>>> my_list = ['r','o','c','k','y']
>>> for i in my_list:
...    print(i,end=' ')
...
r o c k y
>>>

>>> my_iter = iter(my_list)
>>> my_iter.__next__()
'r'
>>> my_iter.__next__()
'o'
>>> my_iter.__next__()
'c'
>>> my_iter.__next__()
'k'
>>> my_iter.__next__()
'y'
>>> my_iter.__next__()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration

>>> while True:
...    print(my_iter.__next__())
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
StopIteration

>>> my_iter = iter(my_list)
>>> while True:
...    print(my_iter.__next__())
...
r
o
c
k
y
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
StopIteration

文件迭代器

My name is Rocky
I love Python
a，hhhhhhh

>>> f = open('test.txt')
>>> for line in f:
...    print(line,end=' ')
...
My name is Rocky
I love Python
a，hhhhhhh >>>

>>> f = open('test.txt')
>>> f.__next__()
'My name is Rocky\n'
>>> f.__next__()
'I love Python\n'
>>> f.__next__()
'a，hhhhhhh'
>>> f.__next__()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration