beginner, idiomatic python

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Aug 26 22:43:02 EDT 2007


En Sun, 26 Aug 2007 22:58:35 -0300, bambam <david at asdf.asdf> escribi�:

> Ok, many environments are capable of cached evaluation
> of functions without variable parameters so
>     range(5)
> is cached, but
>     range(v) is re-evaluated every time. Is this defined
> behaviour?

The range builtin function returns a list, and lists are mutable objects,  
so it must return a *different* list each time.

> That is, is it defined what Python does for
>     for i in f()
> I'm sure it must be, but I haven't seen it yet. If I have
> a user defined function returning a range, is it defined
> that the range function is called on every loop? If I
> have a function returning a range taking a parameter,
>     for i in f(v)
> is it defined that the variable is evaluated for every loop?

Find all the (mostly negative) answers yourself in  
<http://docs.python.org/ref/for.html>

-- 
Gabriel Genellina




More information about the Python-list mailing list