[Tutor] list semantics

Joel Goldstick joel.goldstick at gmail.com
Sat Apr 11 22:53:43 CEST 2015


On Sat, Apr 11, 2015 at 3:21 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sun, Apr 12, 2015 at 05:09:43AM +1000, Steven D'Aprano wrote:
>
>> Almost correct, but not quite. range, like xrange in Python 2, is not a
>> generator, but a custom-made lazy sequence object.
>>
>> py> gen()  # This actually is a generator.
>> <generator object gen at 0xb7bd7914>
>> py> range(1, 10)  # This is not.
>> range(1, 10)
>
> Oops, I forgot to show where gen() came from. Sorry about that, just a
> cut-and-paste error.
>
> py> def gen():
> ...     yield 1
> ...
> py> gen()  # This actually is a generator.
> <generator object gen at 0xb7bd7914>
>
Thanks for the tip Steve
>
>
> --
> Steve
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



-- 
Joel Goldstick
http://joelgoldstick.com


More information about the Tutor mailing list