index in for loops

M

manstey

in for loops like the following:

word='abcade'

for letter in word:
print letter


Is it possible to get the position of letter for any iteration through
the loop?

so for examlpe letter=='a', and I want to know if it is the first or
second 'a' in 'abcade'.

can i do this by looking at a property of letter?
 
W

Wojciech =?iso-8859-2?Q?Mu=B3a?=

manstey said:
in for loops like the following:

word='abcade'

for letter in word:
print letter


Is it possible to get the position of letter for any iteration through
the loop?

for index, letter in enumerate(word):
print index, letter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top