How to iterate over list in python

From DevOps Notebook
Revision as of 23:03, 14 November 2019 by MilosZ (talk | contribs)

Iterate trough list with for loop in python:

# example list
list = [1, 2, 22, 55, 29] 
# for loop 
for i in list: 
	print(i)


Using enumerate() in for loop with list in python

# example list
list = [1, 2, 22, 55, 29] 
# Using enumerate() with for loop 
for i, val in enumerate(list): 
    print (i, ",",val)