Python_Casting
Python_Casting
Casting is when you convert a variable value from one
type another . This is done in python.
The functions are int(),float(),str()
Example:
Integers (int) type
x = int(1)
y = int(2.8)
z = int("3")
print(x)
print(y)
print(z)
y = int(2.8)
z = int("3")
print(x)
print(y)
print(z)
Output: The o/p of program is ‘int’ type
1
2
3
Example:
Float type
x = float(1)
y = float(2.8)
z = float("3")
w = float("4.2")
print(x)
print(y)
print(z)
print(w)
Output: The o/p of program is ‘float’ type
1.0
2.8
3.0
4.2
Example:
String type
x = str("Vedanta") y = str(8) z = str(5.0) print(x) print(y) print(z)
Output: The o/p of program is ‘str’ type
Vedanta
8
5.0
Comments
Post a Comment