#python

Pubblicato il: 30 settembre 2024
sul canale di: 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


In questa pagina del sito puoi guardare il video online #python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Mastering Technology 30 settembre 2024, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 63 volte e gli è piaciuto 6 spettatori. Buona visione!