range() and Definite Iteration

range(stop) returns a sequence of numbers from 0 (the default) up to but NOT including stop, incrementing by 1 (the default). range(5) generates 0, 1, 2…

range(stop)
range(stop) returns a sequence of numbers from 0 (the default) up to but NOT including stop, incrementing by 1 (the default).
• range(5) generates 0, 1, 2, 3, 4
• range(100) generates 0, 1, 2, ..., 98, 99
A simple use of a for loop runs some code a specified number of times using the range() function.
Think of range(5) as generating this list: [0, 1, 2, 3, 4]. The code above is equivalent to:
The loop variable does not have to be used inside the body. If you only want to repeat something a set number of times, ignore it.
range(start, stop)
range(start, stop) counts from start up to but NOT including stop, incrementing by 1 (the default).
Definite iteration
The for loop is an example of a definite iteration. We can determine ahead of time the number of times the loop repeats. Later, we will talk about indefinite iteration, a loop where we cannot predict the number of times a loop repeats.