user3279
0
Q:

python for loop with array

for x in cars:
	print(x) 
3
thisList = [1, 2, 3, 4, 5, 6]

x = 0
while(x < len(thisList)):
    print(thisList[x])
    x += 1
    
# or you can do this:

for x in range(0, len(thisList)):
    print(thisList[x])
    
#or you can do this

for x in thisList:
    print(x)
2
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'
1
for x in range (1, 100, 1):
  print(x)
1
# Python3 code to iterate over a list
list = [1, 3, 5, 7, 9]
  
# Using list comprehension
[print(i) for i in list]
0

New to Communities?

Join the community