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
29 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

+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
• 57,300 points
40 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,210 points
30 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,570 points
110 views
0 votes
1 answer

How to use for loop in Python?

There are multiple ways of using for ...READ MORE

answered Mar 4 in Python by Priyaj
• 57,300 points
36 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 420 views
+4 votes
6 answers
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
46 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
102 views