Facebook Pixel

Type Casting

Similar to type conversion, type casting is explicitly specifying the data type of a value or variable using constructor functions like int(), float(), or str().

Example:

str1 = "7"          
str2 = "3.142"
str3 = "13"
num1 = 29
num2 = 6.67
 
print(int(str1))
print(float(str2))
print(float(str3))
print(str(num1))
print(str(num2))

Output:

7
3.142
13.0
29
6.67