21
Aug

Python For Loop Enumerate


We open ipython for this example first, we will create a list with list comprehension you can find a video on that in the description and We’ll just print out the list real quick. It goes from negative 20 all the way to positive 20 So let’s create a for loop with enumerate enumerate. We’ll go through each value and index. So we will type those variable names here for index value in and numerate and We’ll just print this out with index and then the value To show you how it works and here they are we have the index on the left side starting with zero here And it goes all the way up to positive 40 because there’s 41 numbers in this list And the values They start at negative 20s. That’s the first value in the list notice zero is at index 20 and It goes all the way up to positive 20 So there you have it that is how you use enumerate with for loops in Python

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

There are no comments yet

Why not be the first

Leave a Reply

Your email address will not be published. Required fields are marked *