![]() |
VOOZH | about |
The range() function in Python is used to generate a sequence of integers within a specified range. It is most commonly used in loops to control how many times a block of code runs.
Note: range() returns a lazy iterable, not a full list. It generates numbers dynamically instead of storing them all in memory.. To access elements like a list, convert it using list(range(...)).
Example: This example shows the use of range() to generate numbers starting from 0 up to (but not including) a given value.
0 1 2 3 4
Explanation:
range(start, stop, step)
Parameters:
Return: A range object representing the sequence
Example 1: This example generates numbers starting from a custom value and ending before another value.
5 6 7 8 9
Explanation:
Example 2: This example generates even numbers by skipping values using a custom step size.
0 2 4 6 8
Explanation:
Example 3: This example demonstrates how range() can be used to generate numbers in reverse order by providing a negative step value.
10 8 6 4 2
Explanation: