我认为这项任务的目的是让你了解xrange做什么,iterators是什么。从documentation:This function is very similar to range(), but returns an xrange object
instead of a list. This is an opaque sequence type which yields the
same values as the corresponding list, without actually storing them
all simultaneously. The advantage of xrange() over range() is minimal
(since xrange() still has to create the values when asked for them)
except when a very large range is used on a memory-starved machine or
when all of the range’s elements are never used (such as when the loop
is usually terminated with break). For more information on xrange
objects, see XRange Type and Sequence Types str, unicode, list,
tuple, bytearray, buffer, xrange.
实际上,尝试编写for循环而不是直接使用它:for i in range(.....):
pass
对比:
^{pr2}$
看看会发生什么。在