using range() in for loops

Paul Rubin http
Tue Apr 4 21:58:27 EDT 2006


John Salerno <johnjsal at NOSPAMgmail.com> writes:
> The reason for this distinction comes from the fact that I read a lot
> how using range and for is somewhat discouraged, because it doesn't
> really use a for loop for it's true purpose. So my question is, is
> this just a Python-oriented opinion about for loops, or is it a
> general idea?

Normally you'd use range or xrange.  range builds a complete list in
memory so can be expensive if the number is large.  xrange just counts
up to that number.



More information about the Python-list mailing list