Skip to main content

Type Conversion

Type Conversion



In Python, it's impossible to complete certain operations due to the types involved. For instance, you can't add two strings containing the numbers 2 and 3 together to produce the integer 5, as the operation will be performed on strings, making the result '23'.
The solution to this is type conversion.
In that example, you would use the int function.


>>> "2" + "3"
'23'
>>> int("2") + int("3")
5



Type Conversion



In Python, it's impossible to complete certain operations due to the types involved. For instance, you can't add two strings containing the numbers 2 and 3 together to produce the integer 5, as the operation will be performed on strings, making the result '23'.
The solution to this is type conversion.
In that example, you would use the int function.

>>> "2" + "3"
'23'
>>> int("2") + int("3")
5