Style/efficiency question using 'in'
Joe Strout
joe at strout.net
Fri Apr 23 14:11:46 EDT 1999
In article <3720B3B9.98BED320 at earth.ox.ac.uk>, Nick Belshaw
<nickb at earth.ox.ac.uk> wrote:
> If I do something like :-
>
> ------------------
> def func1():
> return 1,2,3,4,5,6,7,8
>
> for x in func1():
> print x
> ------------------
>
> it works as expected but is the use of a function in a loop undesirable?
> Is the function called once to build the loop or is it called each loop
> increment and therefore undesirable if there is much overhead?
It's called once to build the loop, as you can prove to yourself by
inserting "print 'spam'" into func1().
Cheers,
-- Joe
--
,------------------------------------------------------------------.
| Joseph J. Strout Biocomputing -- The Salk Institute |
| joe at strout.net http://www.strout.net |
`------------------------------------------------------------------'
Check out the Mac Web Directory! http://www.strout.net/macweb.cgi
More information about the Python-list
mailing list