← Go Back
Use the second argument to convert to a different base (defaults to 10). For example:
To convert to a floating point number, use the
How to Convert a String to a Number
To convert a string to an integer, use theint()
built-in function.>>> int("5")
5
Use the second argument to convert to a different base (defaults to 10). For example:
# Hexadecimal conversion.
>>> int("ff", 16)
255
# Binary.
>>> int("101", 2)
5
To convert to a floating point number, use the
float()
built-in:>>> float("3.14")
3.14
🐍 You might also find interesting: