![]() ![]() enumerate() is also used like this within the Python codebase. In the previous section, you saw how to use enumerate() with start to create a natural counting number to print for a user. ![]() In the next few sections, you’ll see some uses of enumerate(). Since the count is a standard Python integer, you can use it in many ways. However, this only slightly limits your flexibility. Keep in mind that enumerate() increments the count by one on every iteration. You should use enumerate() anytime you need to use the count and an item in a loop. Compare this with the previous examples, in which start had the default value of 0, and see whether you can spot the difference. In this example, you pass start=1, which starts count with the value 1 on the first loop iteration. for count, value in enumerate ( values, start = 1 ). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |