Python - Casting
Casting is when you convert a variable value from one type to another. This is, in Python, done with functions such as int() or float() or str().
There may be times when you want to specify a type on to a variable. This can be done with casting. Python is an object-orientated language, and as such it uses classes to define data types, including its primitive types.
Casting in python is therefore done using constructor functions:
##Integers example :
x=int(1)
y=int(2.5)
z=int("6")
print(x)
print(y)
print(z)
===o/p===
1
2
6
## float example :
x=float(1)
y=float(25)
z=float("6")
print(x)
print(y)
print(z)
====o/p====
1.0
25.0
6.0
## strings example :
x=str("a")
y=str(23)
z=str("apple")
w=str(2.6)
print(x)
print(y)
print(z)
print(w)
===o/p===
a
23
apple
2.6