Use the Python range() Function to Generate Sequences of Numbers
In Python, range
is an immutable sequence type, meaning it's a class that generates a sequence of numbers that cannot be modified. The main advantage to the range
class over other data types is that it is memory efficient. No matter how large a sequence you want to iterate over, the range
class only stores the start
, stop
, and step
values (we'll cover these later), not the entire sequence of numbers.
In this guide we'll cover various was to use the range
class.