Built-in Functions
range()
Make a sequence of evenly spaced integers.
range(start, stop=None, step=1)
range() represents an immutable sequence of numbers commonly used for looping a specific number of times in for loops.
Accepts start, stop (exclusive), and step arguments.
Parameters
| Name | Description |
|---|---|
| start | The first number, or the stop number when stop is omitted. |
| stop | The number to stop before. |
| step | How much to add or subtract each time. |
Returns
A range object.
Try it
Run it and change it
numbers = list(range(1, 6, 2)) print(numbers)
Worth knowing
- Memory efficiency: A
rangeobject always takes the same small amount of memory regardless of the sequence size, computing items on demand.