eumneration function in the python

technical talkiess
0

 # enumerate function in the python 

list_one = ["vishal","sarika","komal","lakhan","shubhangi"]


# if you want to print the odd number so you can simply use the loops in the python 


i = 1

for item in list_one:

    if i%2 != 0:

        # f means fstring in the python the varaible is called in the f string simple use {} barces other wise you want to concatinate the variable.

        print(f"Odd number items is : {item}")

    i = i+1


print("\n")

#Now same code using the eumneration function you can use enumerate

# eumneration is adding the counter in the iteration

for index,item in enumerate(list_one):

    if index%2 == 0:

        print(f"Odd number items is : {item}")

    

# if you want to the add start index now you can pass following type ... 3 means which index you started by default :- 

for index,item in enumerate(list_one,3):

    if index%2 == 0:

        print(f"Odd number items is : {item}")

    

Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)