Range datatype:
The range data type represents
a sequence of numbers. The numbers in the range are not modifiable. Generally, range is used for repeating a ‘for loop’ for a specific numbers of times.
Or
It is a collection of numbers
in the form of the list.
Creating range data type:
>>> r=range(2,10) #one range data type is created, r is the variable which points to elements
>>> print(r)
range(2, 10)
#Displaying the elements in the range data type:
>>> for i in r:
print(i)
2
3
4
5
6
7
8
9
>>>
# range data type is created from 3rd to below 10, each element is incremented by 2
>>> r=range(3,10,2)
>>> for i in r:
print(i)
3
5
7
9
>>> r=range(3,10,2) #displays the numbers from 3 to below 10, every element is incremented by 2
>>> for i in r:
print(i)
3
5
7
9
r=range(0,15,3)
#numbers starts from 0 to
below 15, and each element is incremented by 3
Output:
>>> r=range(0,15,3)
>>> for i in
r:print(i)
0
3
6
9
12
>>>Next topic : dictionary data type
You may like the following posts:
Built-in Data types
No comments:
Post a Comment