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

Rune Strand rune.strand at gmail.com
Mon Apr 3 11:39:52 EDT 2006


JuHui wrote:
> >>> a='String'
> >>> for x in a:
> ...     print x
> ...
> S
> t
> r
> i
> n
> g
> >>>
>
> can I get the index number  of a in the upon loop within for x in a
> loop?

for x, y in enumerate(a)
    print x, y




More information about the Python-list mailing list