Type Casting and Conversion
Type casting is converting one data type to another. Python makes it simple using built-in functions.
Common Conversions
int()
– Convert to integerfloat()
– Convert to floatstr()
– Convert to stringbool()
– Convert to boolean
Examples
num_str = "10"
num = int(num_str) # 10 as an integer
price = 9.99
price_str = str(price) # "9.99"
Always ensure the conversion is valid to avoid errors.