Conversion in python
For Professionals and Freshers |
Typecasting :int() function
Example : int(123.456)
output : 123
int(10+20j)
output : error - we cant convert complex to int
int(True) : 1
int(False) :0
int("10"):10
int("12.12") =error , converting string to int possible but data should be decimal
Typecasting :float() function
float(10) = 10.0
float(True) =1.0
float(Flase)=0.0
float("10")=10.0
float(10.5)=10.5
typecasting : bool() function
bool(0) =False
bool(1)=True
bool(-10)=True
bool(0.0)=False
bool(0.01)=True
bool(10+20j)=True
Note : In complex number if both real and imaginary is non zero then only we get True.
bool(')=Flase
Note : For blank str bool returns False
bool("Govind") = True
Comments
Post a Comment