Python range(): Represent Numerical Ranges
A range
is a Python object that represents an interval of integers. Usually, the numbers are consecutive, but you can also specify that you want to space them out. You can create ranges by calling range()
with one, two, or three arguments, as the following examples show:
In each example, you use list()
to explicitly list the individual elements of each range. You’ll study these examples in more detail soon.
A range
can sometimes be a powerful tool. However, throughout this tutorial, you’ll also explore alternatives that may work better in some situations. You can click the link below to download the code that you’ll see in this tutorial:
Construct Numerical Ranges
In Python, range()
is built in. This means that