Iteration index
Alex Martelli
aleaxit at yahoo.com
Thu May 31 18:20:50 EDT 2001
"Marek Augustyn" <maug at kopnet.gliwice.pl> wrote in message
news:9f63lo$rb0$1 at zeus.polsl.gliwice.pl...
> Hello!
>
> 1. Do I have to use additional variable when I want to know iteration
index?
> Example:
>
> s = ('a', 'b', 'ala', 'a')
> i = 0 # additional variable
> for el in s:
> print i, el
> i += 1
You may work this in several ways, such as the one you used, or:
for i in range(len(s)):
print i, s[i]
or
for i, el in zip(range(len(s)), s):
print i, el
> 2. Are there block comments in Python? (like /* */ in C)
Not quite, but triple-quoted strings can often serve a similar
purpose of "commenting out" blocks of lines.
Alex
More information about the Python-list
mailing list