Description
Once you learn about for loops in Python, you know that using an index to access items in a sequence isn't very Pythonic. So what do you do when you need that index value? In this tutorial, you'll lea ...
Summary
- In Python, a for loop is usually written as a loop over an iterable object.
- >>> >>> print(values[0])a You can see in this example that accessing values with the index 0 gives the first element, a.
- However, there are many times when you might not want the count from enumerate() to start at 0.
- On the third line of check_whitespace(), enumerate() is used in a loop over lines.
- For each elem in sequence, you yield control back to the calling location and send back the current values of n and elem.