Python Language / Python Type Casting

It is also called as data conversion / type conversion.It is a process of converting one data type into another one.

Example
Fucntion Converts to Type Example Output
int()  Integer literal a = int(2)
b = int(4.5)
print("a=", a)
print("b=", b)
a= 2
b= 4
float()  Float literal a =  float ( 2 )     
b =  float ( 2.6)
c =  float ( "4" )   
d =  float ( "4.9" )
print("a=", a)
print("b=", b)
print("c=", c)
print("d=", d)
a= 2.0
b= 2.6
c= 4.0
d= 4.9
str()  String literal a =  str ( "q1" ) 
b =  str ( 2 )    
c =  str ( 5.0 )  
print("a=", a)
print("b=", b)
print("c=", c)
a: q1
b: 2
c: 5.0


Home     Back