The range() function allows counting in for loops as well.
range() generates a sequence of integers between a starting integer that is included in the range, an ending integer that is not included in the range, and an integer step value.
The sequence is generated by starting at the start integer and incrementing by the step value until the ending integer is reached or surpassed.
The range() function can take up to three integer arguments:
range(Y) generates a sequence of all non-negative integers less than Y.
Ex: range(3) creates the sequence 0, 1, 2.
range(X, Y) generates a sequence of all integers >= X and < Y.
Ex: range(-7, -3) creates the sequence -7, -6, -5, -4.
range(X, Y, Z), where Z is positive, generates a sequence of all integers >= X and < Y, incrementing by Z.
Ex: range(0, 50, 10) creates the sequence 0, 10, 20, 30, 40.
range(X, Y, Z), where Z is negative, generates a sequence of all integers <= X and > Y, incrementing by Z.
Ex: range(3, -1, -1) creates the sequence 3, 2, 1, 0.