Python Shortcut
Enumerate()
It adds an index or counter to an iterable (i.e lists, tuple or strings). It takes two parameters.
1. iterable
2. start ( by default its value is 0), but one can change according to the requirement.
Code:
fruits=['apple','mango','litchi']
print(list(enumerate(fruits,start=1)))
Output:
[(1, 'apple'), (2, 'mango'), (3, 'litchi')]
Code:
for i,fruit in enumerate(fruits):
print(i,fruit)
Output:
0 apple
1 mango
2 litchi
#function #enumerate #pythonprogramming #shortcut #index #variables #iterable #like #lists #tuples #strings #pycharm #ide
#like #share #subscribemychannel
On this page of the site you can watch the video online #python with a duration of hours minute second in good quality, which was uploaded by the user Mastering Technology 30 September 2024, share the link with friends and acquaintances, this video has already been watched 63 times on youtube and it was liked by 6 viewers. Enjoy your viewing!