simple question re list iteration semantics

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Tue Apr 21 22:14:21 EDT 2009


On Tue, 21 Apr 2009 21:06:46 -0400, Esmail wrote:


> Given a list 'li', I can always do this to iterate through all items in
> order:
> 
> for i in range(0, len(li)):
>      print li[i]
> 
> Will this always be equivalent to
> 
> for i in li:
>      print i

For lists, yes, that will always be equivalent, and the second one is 
considered more Pythonic.



-- 
Steven



More information about the Python-list mailing list