Python's range() vs xrange() Functions By: Rajesh P.S.Both range() and xrange() are intrinsic functions in Python, serving the purpose of generating integers within specified ranges. The deliberation regarding the comparison between range() and xrange() gains significance primarily when operating...
xrange不再存在。range 创建一个列表,因此,如果执行range(1, 10000000)它将在内存中创建一个包含9999999元素的列表。 xrange是一个生成器,因此它是一个序列对象,是一个懒惰求值的对象。 的确如此,但是在 Python 3 中, range()将由Python 2 xrange() 。如果需要实际生成列表,则需要执行以下操作: list(...