I'm getting this error in my code:
ValueError: invalid literal for int() with base 10: ''.
What does it mean? Why does this happen and how to solve it?
P粉5783439942024-03-26 14:27:50
This error message means that the string supplied to int
cannot be parsed as an integer. The last part after :
displays the provided string.
In the case of the problem description, the input is an empty string , written as ''
.
Here's another example - strings representing floating point values cannot be converted directly with int
:
>>> int('55063.000000') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '55063.000000'
Instead, first convert to float
:
>>> int(float('55063.000000')) 55063