examples of for loop in python
Example 1: python for loop
A for loop iterates through an iterable, may that be an array, a string, or a range of numbers
#Example:
myArr = ["string 1", "string 2"]
for x in myArr:
print(x)
#Returns "string 1", "string 2". In here the x is an iterator and does not need to be defined.
Example 2: python for loop
nums = ['one', 'two', 'three']
for elem in nums:
print(elem)
Example 3: python for loop
my_list = ["milk", "coffee", "bread"]
# i stands for iterator
for i in my_list:
print(i) # prints every element of my_list