enumerate() function in python adds counter to a iterable and returns it in the enumerate python program.
Syntax : -
enumerate(iterable, start=0)
- Two parameters are used the first one is an object which is accept the iteration.
- The second one is start parameters which is a starting point of counting but it's optional. If start is extinct the it's take 0 at start.
- enumerate() function return the object after adding the counter to an iterable.
Example Program for enumerate() in Python
grocery = ['bread', 'Tea', 'jam'] enumerateGrocery = enumerate(grocery) print(type(enumerateGrocery)) # converting the gienvalue into a list print(list(enumerateGrocery)) # changing the default counter enumerateGrocery = enumerate(grocery, 10) print(list(enumerateGrocery))
OUTPUT
Program for enumerate() in Python |
0 comments:
Post a Comment