python2和3中的机制不同
class Foo(object):
def __init__(self):
self.items = range(3)
def __getitem...__(self, i):
print('__getitem__', i)
return self.items[i]
foo1 = Foo()
foo2 = Foo()
print..., foo2))
# for s1, s2 in zip(foo1, foo2):
# print(s1, s2)
python2
# 输出:
# 提前已经遍历了一遍,组成新的列表了
('__getitem...__', 0)
('__getitem__', 0)
('__getitem__', 1)
('__getitem__', 1)
('__getitem__', 2)
('__getitem__', 2...)
('__getitem__', 3)
[(0, 0), (1, 1), (2, 2)]
python3
# 输出:
可以看到python2