simple question re list iteration semantics

Steven D'Aprano steven at
Wed Apr 22 04:14:21 CEST 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.


More information about the Python-list mailing list