“Python dla INDEKS I BET” Kod odpowiedzi

Python dla INDEKS I BET

# get index and value in python for loop

your_list = ['apple', 'banana', 'orange']

for index, value in enumerate(your_list):
    print(index, value)

# will print the following:
#   0 apple
#   1 banana
#   2 orange
Dark Dotterel

indeks Python GT w cyklu

my_list = [0,1,2,3,4]
for idx, val in enumerate(my_list):
    print('{0}: {1}'.format(idx,val))
#This will print:
#0: 0
#1: 1
#2: 2
#...
Outrageous Oryx

Iteracja z indeksem dla pętli Python

colors = ["red", "green", "blue", "purple"]
ratios = [0.2, 0.3, 0.1, 0.4]
for color, ratio in zip(colors, ratios):
    print("{}% {}".format(ratio * 100, color))
Trained Tuna

Odpowiedzi podobne do “Python dla INDEKS I BET”

Pytania podobne do “Python dla INDEKS I BET”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu