Type Casting Techniques in Python

The purpose of Type Casting Techniques is in python is that "To Convert one Type of value into Another Possible Type of value".
in python programming we have 5 fundamentals Type Casting Techniques They are:
1.int()
2.float()
3.bool()
4.complex()
5.str()
1.int(): int() is used for converting possible Type of value into int type value.
Synatx: varname=int(float/complex/bool/str)
ex: float type into int type:
a=12.34
print(a,type(a)) ------>12.34 <class 'float'>
b=int(a)
print(a,type(a)) ----->12 <class 'int'>
ex2: bool type into int type:
a=True
print(a,type(a)) ----->True <class 'bool'>
b=False
print(b,type(b)) ----->False <class 'bool'>
c=int(a)
print(c,type(c))-----> 1 <class 'int'>
d=int(b)
print(d,type(d))-----> 0 <class 'int'>
Subscribe to my newsletter
Read articles from sindhu m directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
