Search This Blog

Data Type in Python, What is Data Type in Python

The data type is used to provide a pattern, size, and memory allocation of data using variable, constant, and method.

Python uses datatype internally in the program, no need to write a datatype declaration in the program because python provides flexibility to the identifier to contain multiple types of data using a single name identifier.

Type of Datatype:-

Primitive Type 
1 int :-  a=10

2 float    a=12.34

3 String:-  Collection of Char's

s= "data"           HTML Content will be rendered in double quote

s= 'data'             Html content will not be rendered content

s= """data"""    it support paragraph pattern or multiline statements

''' comment '''     multiline comment


4 boolean:-

it is used to create checkpoint or true|false value in the variable

by default, if statement, loop statement return a boolean value



b = True

b= False



Derived Datatype:-

this type of data is specially created for Python Script.


1  LIST:-  it is used to contain a set of elements using an index from 0 to size-1 whose value can be change

2 TUPLE:-  it is used to contain a set of elements using the index value pair whose value can not be changed

3 DICTIONARY:-  it is used to contain a set of elements using key: value pair 

4 Set:-  It is used to display elements randomly.

5 DATETIME:-  it is used to contain current data and time 

6 Class:-  it is used to create User-define type

7 Complex:-  it is used to contain a complex number

a = 2+3j    j means iota 


........................................................................................................

Predefine function in Python for Data type


type():-   it is used to represent datatype of any identifier in Python


a=10
print(type(a))
a=20.2
print(type(a))
a=2+3j
print(type(a))
a=(10,20)
print(type(a))
a=[10,20]
print(type(a))
a={'a':10,'b':20}
print(type(a))
a=True
print(type(a))
a='hello'
print(type(a))
a="hello"
print(type(a))
a="""hello"""
print(type(a))

int():-  this method is used to convert numeric String to integer

a= "123"
a = int(a)  #123

float():-  this method is used to convert numeric float String or integer to float

a=12
a = float(12)  #12.0

a= "12.34"
a=float(a)  #12.34

str():-  this method is used to convert int, float type value to String type

a= 12
b=str(a)  #"12"

b = str(12.34)  #"12.34"


Q WAP to convert temperature from Celsius to Fahrenheit?

Q WAP to perform multiplication of a complex number using complex datatype?

Q WAP to evaluate the middle number in three-digit numbers based on order ?


a= 132   #2

a=456  #5

a = 546  #5

Q WAP to print data in the single quote and double quote

 "Welcome in SCS"
 'Welcome in Python'
 '\n hello \n"










Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post