python学习资料
在i18n.linux.net.cn上的我看了,刚开始说的还挺详细,后面的...........唉.......谁能给我详细讲讲
class Reverse:
"Iterator for looping over a sequence backwards"
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
>>> for char in Reverse('spam'):
print char 发错地方了
页:
[1]