Type Casting

 

Type Casting

Similar to type conversion, type casting is done when we want to specify a type on a variable. 

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