| start | (optional) default = 0 , The start position of the range |
| stop | ( required ), range should Stop before this position |
| step | ( optional ) default =1 , step to consider for the range |

x=range(5) # 5 is stop value
print(list(x)) # [0, 1, 2, 3, 4]
With start and stop values
x=range(2,5) # 2 is start ,5 is stop value
print(list(x)) # [2, 3, 4]
x=range(2,5,2) # 2 is start ,5 is stop,2 is step value
print(list(x)) # [2, 4]
my_list=[5,40,10]
for i in range(*my_list): # unpacking the list inside range
print(i)
Output
5
15
25
35
We can use range to create a list with elements
x=range(5,50,10) # range with start=5,stop=50, step=10
my_list=list(x) # list created
print(my_list)
Output
[5, 15, 25, 35, 45]
To transform or filter values from range() while creating a list, see
list comprehension with range().
x=range(5,-10,-3)
print(list(x)) # [5, 2, -1, -4, -7]
x=range(5) # 5 is stop value
print(type(x)) # <class 'range'>
range() returns immutable object, so we can't change the elements.
for x in range(5):
print(x)
Output
0
1
2
3
4
All Built in Functions in Python filter()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.