The for statement iterates over a structure ("a sequence of something", list, tuple, set, dictionary, etc.)
A general syntax is like:
for ELEMENT in STRUCTURE:
statememn1
statement2
...
Example for iterating over a list:
mylist = [1, 'two', 'xyz', 8.35, True]
for element in mylist:
print(element)
#output
1
two
xyz
8.35
True
We can use range() function in for to iterate over a sequence of numbers, or over a part of structure elements. For example, if we need to iterate/touch over first 2 elements:
mylist = [1, 'two', 'xyz', 8.35, True]
for i in range(2):
print(mylist[i])
#output
1
two
General syntax for range function is range(start, stop, step=1), based on this we can iterate with other step different than 1, also iterate not only from the beginning of the structure but over a subset of elements, example:
mylist = [1, 'two', 'xyz', 8.35, True]
for i in range(1,3):
print(mylist[i])
#output
two
xyz
Here range function return values from start value till end value minus 1, i.e. range(1,3) give 1,2 values.