Type Casting is the process of converting data of one type to another
Python has two types of conversion:
- Implicit - automatic type conversion
- Explicit - manual type conversion
Example
smaller data types implicitly get converted to larger data types to avoid loss of data
Python can’t perform implicit conversions on mis-matched data types
can’t add str
and int
for example: '12' + 23
Explicit Conversions
users convert the data type of an object to required data type
you can use built-in functions like int()
, float()
, str()
to perform explicit type conversions