Tuesday, 28 May 2019

range data type



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
>>>

Any doubts you can mail: rajendra.apssdc@gmail.com


Next topic      : dictionary data type
Previous topic: frozenset datatype

You may like the following posts:
  Built-in Data types

No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(&qu...