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]
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
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.