can I get the index number in for x in y loop?

Luigi luigipaioro at libero.it
Mon Apr 3 11:36:50 EDT 2006


Try this:

>>> a='String'
>>> i=0
>>> for x in a:
...   print i, x
...   i+=1
...
0 S
1 t
2 r
3 i
4 n
5 g




More information about the Python-list mailing list