Python: Convert Int, Float, String

By Xah Lee. Date: .

Python doesn't automatically convert between {int, float, string}.

Convert float to int

print(int(3.2))
# 3

Convert int to float

print(float(3))
# 3.0

Convert number to string

Convert string to number

# string to int
print(int("123"))
# 123
# string to float
print(float("123.45"))
# 123.45

Python, number and arithmetic