Answers for "how to use for loop to print list in python"

5

python for loop with array

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'
Posted by: Guest on July-18-2020
0

how to print list using for loop in python

list = [1,"bob",4,"life",5]
# with loop
for i in list:
    print(i)  
>>> 1
bob
4
life
5

x = [print(i) for i in list]
>>> 1
bob
4
life
5

# without loop
print(*list, sep = ", ")
>>> 1, bob, 4, life, 5

print(' '.join(map(str, list)))
>>> 1 bob 4 life 5
Posted by: Guest on August-06-2021
2

print all elements in list python

# using for loop
scores = [11, 12, 13, 14, 15, 16]
for score in scores:
    print(score)
Posted by: Guest on May-14-2020

Code answers related to "how to use for loop to print list in python"

Python Answers by Framework

Browse Popular Code Answers by Language