OneBite.Dev - Coding blog in a bite size

loop array in python

Code snippet on how to loop array in python

  example_list = [1, 5, 10, 15, 20]

for item in example_list:
  print(item)

This code shows how to loop an array in python. The first line creates an array called example_list and assigns it values. The second line begins a for loop which iterates through the array. The keyword ‘item’ is used to represent each element of the array. The third line prints out each element of the array one at a time until the loop reaches the end of the array. In this case, once the loop reaches the last item in the array (20), it will exit the loop.

python