#python

Publicado em: 30 Setembro 2024
no canal de: Mastering Technology
63
6

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


Nesta página do site você pode assistir ao vídeo on-line #python duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Mastering Technology 30 Setembro 2024, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 63 vezes e gostou 6 espectadores. Boa visualização!