Get index in for loop

0 votes
When I loop through a list using a for loop, how do I access the loop index? Is there a "pythonic" way of doing this or should I initialize a loop variable and do it the usual way?
Apr 24, 2018 in Python by broly
544 views

1 answer to this question.

0 votes

Use enumerate():

for index, value in enumerate(array):
    print(index, value)
answered Apr 24, 2018 by Nietzsche's daemon
• 4,260 points

Related Questions In Python

0 votes
0 answers
+1 vote
1 answer

Accessing the index in 'for' loops?

Using an additional state variable, such as ...READ MORE

answered Aug 28, 2018 in Python by Priyaj
• 58,020 points
700 views
0 votes
1 answer

Break for loop in an if statement

You'll need to break out of each ...READ MORE

answered Oct 23, 2018 in Python by SDeb
• 13,300 points
869 views
0 votes
1 answer

How to break for loop in an if statement

You can break out of each loop ...READ MORE

answered Nov 16, 2018 in Python by Jino
• 5,820 points
3,011 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,071 views
0 votes
1 answer

Unique identification for data items in Python

Try the UUID module of Python. For example, ...READ MORE

answered Apr 17, 2018 in Python by Nietzsche's daemon
• 4,260 points
1,150 views
0 votes
1 answer

Slice notation in Python for string reversal

The slice notation is [start:end:step]. Step = ...READ MORE

answered Apr 25, 2018 in Python by Nietzsche's daemon
• 4,260 points
678 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP