What does enumerate mean?

0 votes

I am using tkinter in Python and came across the following code:

for row_number, row in enumerate(cursor):
 

I was wondering whether anyone could explain what enumerate means in this context?

Oct 11, 2018 in Python by ana1504.k
• 7,870 points
22 views

1 answer to this question.

0 votes
The enumerate() function adds a counter to an iterable.

So for each element in the cursor, a tuple is produced with (counter, element); the for loop binds that to row_number and row, respectively.

Demo:

>>> elements = ('foo', 'bar', 'baz')
>>> for elem in elements:
...     print elem
...
foo
bar
baz
>>> for count, elem in enumerate(elements):
...     print count, elem
...
0 foo
1 bar
2 baz
answered Oct 11, 2018 by SDeb
• 13,160 points

Related Questions In Python

+4 votes
3 answers

What does these operator mean **, ^, %, // ?

** - Performs exponential (power) calculation on ...READ MORE

answered Apr 11, 2018 in Python by anto.trigg4
• 3,420 points
41 views
0 votes
1 answer

What does ' -> ' mean in Python function definitions?

It's a function annotation. In more detail, Python 2.x ...READ MORE

answered May 22, 2018 in Python by charlie_brown
• 7,720 points
53 views
0 votes
1 answer

What does AF_INET mean?

AF_INET refers to Address from the Internet ...READ MORE

answered Jul 3 in Python by Wajiha
• 1,920 points
11 views
+1 vote
3 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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 216 views
0 votes
1 answer

What does [:] mean?

It's a slicing, and what it does ...READ MORE

answered Jan 16 in Python by SDeb
• 13,160 points
16 views
0 votes
1 answer

What does the return statement do in Python?

The print() function is use to write ...READ MORE

answered Oct 1, 2018 in Python by SDeb
• 13,160 points
67 views