Python throws the error, ValueError: invalid literal for int() with base 10:”, when you pass a float string in int()
function. Although, you can pass the string in float()
function.
Consider this example –
>>> int('5555.00')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '5555.00'
PythonCopy
The problem with this code is that you are passing a float string '5555.00'
in int() function. The correct way of doing this is to first convert it into float()
and then into int()
.
#python #error #python error #python-short