“comment traverser un tableau en python” Réponses codées

Python pour boucle avec tableau

foo = ['foo', 'bar']
for i in foo:
  print(i) #outputs 'foo' then 'bar'
for i in range(len(foo)):
  print(foo[i]) #outputs 'foo' then 'bar'
i = 0
while i < len(foo):
  print(foo[i]) #outputs 'foo' then 'bar'
Arrogant Anteater

boucle python via la liste

list = [1, 3, 6, 9, 12] 
   
for i in list: 
    print(i) 
Grepper

itérer à travers un tableau Python

colors = ["red", "green", "blue", "purple"]
i = 0
while i < len(colors):
    print(colors[i])
    i += 1
Elegant Emu

bouclage du tableau python

array = ["Var1","Var2","Var3"]
for i in range(len(array)):
  print(array[i])
  
#Output#
#Var1
#Var2
#Var3
DatMADCoder

tableau de boucle python

num = [int(d) for d in str(input("Enter the number:"))]
even,odd = 0,0
for i in range(0,len(num)):
    if i % 2 ==0:
        even = even + num[i]
    else:
        odd = odd + num[i]

print(abs(odd-even))

# code contributed by Shubhanshu Arya PrepInsta Placement Cell Student
Wrong Willet

comment traverser un tableau en python

array = ['cheese', 'milk', 'bread']
for i in array:
 	print(i) # will print out 'cheese' 'milk' and 'bread' to the console
i = 0
while i < array:
  print(array[i]) #will print out 'cheese' 'milk' and 'bread' to the console
  
for i in range(len(array))
	print(i) #will print out 'cheese' 'milk' and 'bread' to the console
 
#variable doesn't have to be i in for loop for example:

for ingredients in array:
  print(i) #will print out 'cheese' 'milk' and 'bread' to the console
 #this can help you understand what the for loop is doing better
Alive Angelfish

Réponses similaires à “comment traverser un tableau en python”

Questions similaires à “comment traverser un tableau en python”

Plus de réponses similaires à “comment traverser un tableau en python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code