Tags
Language
Tags
April 2024
Su Mo Tu We Th Fr Sa
31 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 1 2 3 4

Real Python - Looping With Python enumerate()

Posted By: lucky_aut
Real Python - Looping With Python enumerate()

Real Python - Looping With Python enumerate()
Duration: 28m | MP4 | Video: h264, 1920x1080 | Audio: AAC, 44.1 KHz, 2 Ch | 94.5 MB
Genre: eLearning | Language: English

In Python, a for loop is usually written as a loop over an iterable object. This means that you don’t need a counting variable to access items in the iterable. Sometimes, though, you do want to have a variable that changes on each loop iteration. Rather than creating and incrementing a variable yourself, you can use Python’s enumerate() to get a counter and the value from the iterable at the same time!

In this course, you’ll see how to

Use enumerate() to get a counter in a loop
Apply enumerate() to display item counts
Implement your own equivalent function to enumerate()
Unpack values returned by enumerate()