1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
>>> a = iter(range(
10
)) #创建一个迭代器
>>> a
<listiterator object at
0x7f251917ec10
>
>>> a.next()
0
>>> a.next()
1
>>> a.next()
2
>>> a.next()
3
>>> a.next()
4
>>> a.next()
5
>>> a.next()
6
>>> a.next()
7
>>> a.next()
8
>>> a.next()
9
>>> a.next()
Traceback (most recent call last):
File
"<stdin>"
, line
1
,
in
<module>
StopIteration
|
1
2
3
4
5
6
7
8
9
10
11
|
>>> f = file(
'student_info.txt'
)
>>> f.next()
'stu1101 mingjia.xu 275896019@qq.com 263 SystemAdmin 18810404260\r\n'
>>> f.next()
'stu1102 Yangjiansong jason@s156.com A8music SystemAdmin 13601247960\r\n'
>>> f.next()
'stu1103 zouxinkai zouxinkai_2006@126.com jishubu systemadmin 1861214111'
>>> f.next()
Traceback (most recent call last):
File
"<stdin>"
, line
1
,
in
<module>
StopIteration
|
1
2
3
4
5
6
7
8
9
|
>>> f = file(
'student_info.txt'
)
>>> f.readline()
'stu1101 mingjia.xu 275896019@qq.com 263 SystemAdmin 18810404260\r\n'
>>> f.readline()
'stu1102 Yangjiansong jason@s156.com A8music SystemAdmin 13601247960\r\n'
>>> f.readline()
'stu1103 zouxinkai zouxinkai_2006@126.com jishubu systemadmin 1861214111'
>>> f.readline()
''
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
>>> a = iter(range(
10
))
>>>
while
True:
... a.next()
...
0
1
2
3
4
5
6
7
8
9
Traceback (most recent call last):
File
"<stdin>"
, line
2
,
in
<module>
StopIteration
|