How to typecast in python?

Typecasting means to convert a variable of one datatype to other datatype. In python in some situation it becomes necessary to convert one datatype to another datatype. We can do this in by the in built functions in python like int(), float(), str(), etc.
- int()- This function helps to convert any datatype to integer.
e.g.,
a="222" print(int(a))
output- 222
- float()- This function helps us to convert any datatype to floating point numbers.
e.g.,
a=22 print(float(a))
output- 22.00
- str()- This function converts any datatype to string.
e.g.,
a=22 b=str(a) print(type(b))
string
In this way we can type cast in python. There are many more functions like hex(), complex(), etc
Subscribe
Login
Please login to comment
0 Discussion