[a,b,c,d] = 1,2,3,4

Terry Reedy tjreedy at udel.edu
Wed Aug 26 17:16:46 CEST 2015


On 8/26/2015 8:21 AM, Tim Chase wrote:

>> a, b, c = (x for x in range(3)) # a generator for instance
>
> Since range() *is* a generator, why not just use

In Python 3, range is a sequence class with a separate iterator class

 >>> r = range(3)
 >>> r
range(0, 3)
 >>> iter(r)
<range_iterator object at 0x00000000034682D0>

Like all sequences, a range object can be iterated multiple times as a 
new iterator is used each time.

 >>> list(r)
[0, 1, 2]
 >>> list(r)
[0, 1, 2]

-- 
Terry Jan Reedy



More information about the Python-list mailing list