Python enumerate function #python #coding #programming

Akansha Yadav shows how Python's enumerate() function lets you loop through a list and get both the index and the value at once. She demonstrates with a fruit list, printing outputs like "apple at index 0" using f-string formatting.
Chapters
Hello everyone, welcome back to my YouTube channel. In today's video, we will be learning about enumerate function in Python. Enumerate function is basically to iterate over any particular, like, list or tuple or something like that. You can iterate over it while keeping a track of both the things, like index and the position, both the things. So let's create a program for the same. I'm creating a fruits list where I'm storing 4 fruits. Then following up with the for loop where I am going to write two local variables. One is going to be the index, another one is going to be the fruit, and iterating it using enumerate function and passing fruits as a function argument. Then printing both the things, the index and the fruit. So let's run this and let's see what is going to be the output. In the output we will get apple at the index 0, banana at index 2, 1, and then cherry at index 1, 2, and then date at index 3. So here we are getting the same output. So in this we are getting all 3 outputs. Why we are getting all 3 output? Because we are using the formatting in the strings, and where we have mentioned both the things, index and the fruit. Index over here, if I will show you over here, if you can see in line number 5, we have written index in the curly brackets because we are using formatting, string formatting way, which is getting printed using the enumerate function, in which we are passing fruit as a argument, basically a parameter for a function. This is a built-in function, but still you need a parameter. So in that case, we are passing parameter which has 4 lists. So if you like the video, don't forget to subscribe the channel.










