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,910 points
583 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,300 points

Related Questions In Python

+4 votes
3 answers

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

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

answered Apr 12, 2018 in Python by anto.trigg4
• 3,440 points
1,310 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 23, 2018 in Python by charlie_brown
• 7,720 points
831 views
0 votes
1 answer

What does AF_INET mean?

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

answered Jul 3, 2019 in Python by Wajiha
• 1,960 points
4,497 views
0 votes
0 answers

What does NameError: name 'withdrawal' is not defined mean ?

READ MORE

Jun 6, 2020 in Python by Shanice
• 120 points

recategorized Jun 8, 2020 by Gitika 848 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,347 views
0 votes
1 answer
0 votes
1 answer

What does [:] mean?

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

answered Jan 16, 2019 in Python by SDeb
• 13,300 points
2,512 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,300 points
1,310 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