Python – How to parse a string to a float or int

floating pointintegerparsingpythontype conversion

In Python, how can I parse a numeric string like


to its corresponding float value,


? Or parse the string "31" to an integer, 31?

I just want to know how to parse a float str to a float, and (separately) an int str to an int.

Best Answer

>>> a = "545.2222"
>>> float(a)
>>> int(float(a))