Tuesday 14 April 2020

Type Casting




Type Casting
We can convert one type value to another type. 
This conversion is called Typecasting or Type coersion. 
The following are various inbuilt functions for type casting.
1. int()
2. float()
3. complex()
4. bool()
5. str()
 
 
1.int():

We can use this function to convert values from other types to int




2. float():
 
We can use float() function to convert other type values to float type. 




 3. complex():
We can use complex() function to convert other types to complex type.
 
Form-1: complex(x) 

We can use this function to convert x into complex number with real part x and imaginary part 0.



Form2: complex(x,y): 

We can use this method to convert x and y into complex number such that x will be real part and y will be imaginary part. 






 4. bool():

We can use this function to convert other type values to bool type.





 
 
 
5. str():
We can use this method to convert other type values to str type



No comments:

Post a Comment