On Wed, 28 Apr 2021 at 22:18, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote: <snip> > The old range() returned a list, and said list could (in your example) > contain 42. The current range() (equivalent to former xrange() ) is not a > container as retrieving values consumes them from the range.
A nitpick -- retrieving values from a range doesn't consume them: ``` >>> r = range(10) >>> r range(0, 10) >>> list(r) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(r) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> r[0] 0 >>> r[3] 3 >>> list(r) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ``` range objects are iterables, not iterators. We can see the consuming behaviour I think you are referring to by calling iter(): ``` >>> i = iter(r) >>> next(i) 0 >>> list(i) [1, 2, 3, 4, 5, 6, 7, 8, 9] ``` -- Matt Wheeler http://funkyh.at -- https://mail.python.org/mailman/listinfo/python-list