range()

range(start,stop,step) returns sequence of numbers ( Immutable ).
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
range() with start and  stop positions
Start, stop and step values are indices of a range.

If one value is given then it is considered as stop value as default start is 0 and step value is 1.
If two values are given then it is considered as start and stop values and step value is set to 1
If three values are given then they are considered as start , stop and step values.

creating range object

With only stop value.
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]

With start , stop and step values
x=range(2,5,2)    # 2 is start ,5 is stop,2 is step value
print(list(x))    # [2, 4]

Using negative numbers

x=range(5,-10,-3)
print(list(x)) # [5, 2, -1, -4, -7]

range data type

By using type()
x=range(5)      # 5 is stop value
print(type(x))  # <class 'range'>
range() returns immutable object, so we can't change the elements. For loop to display elements.
for x in range(5):
 print(x)
Output
0
1
2
3
4
All Built in Functions in Python filter()


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer