迭代器是访问集合元素的一种方式。迭不会退后往前只能迭代器。结束完被访问所有元素直到,开始访问第一个元素的集合从对象代器。优点:不需要事先准备好整个迭代过程中的所有元素。适合遍历一些巨大或是无限的集合。
特点:
1.访问者不需要关心迭代器的内部结构,仅需通过next(方法不断去取下一个内容)
2.不能随机访问集合中的某个值
3.访问到一半时不能往回退
4.便于循环比较大的数据集合,节省内存
names=iter(['zy','zlj','cy'])
print(names._next_())-----zy
print(names._next_())-----zlj
print(names._next_())-----cy
#print(names.next())-----cy
f.read()
f.readline()
for line in f:
print line