range() and Definite Iteration
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.