


Print int(x) Output Traceback (most recent call last): The error ValueError: Invalid literal for int() with base 10: will be thrown as an empty string that can not be converted to an integer. In the example below, an attempt is made to pass an empty string to the build in int() function. If the build in int() function is called with a string argument that contains an empty string, or contains a value other than an integer, or contains a float value, this error can be reproduced. ValueError: invalid literal for int() with base 10: '' Traceback (most recent call last):įile "/Users/python/Desktop/test.py", line 1, in The stack trace shows the line that the int() build in function fails to parse to convert an integer from a string or a number. The error ValueError: Invalid literal for int() with base 10: will be shown as below the stack trace. The int() build in function displays the error message that shows you the exact string you were trying to parse as an integer. The int() function converts the string to an integer if the string is a valid representation of the integer and validates against the base value if specified (default is base 10). If the string is empty or contains a value other than an integer, or if the string contains a float, the error ValueError: Invalid literal for int() with base 10: will be thrown. The integer can also have negative numbers. The digits are supposed to be between 0 and 9. The default base for the int() buit-in function is 10. The int() function converts the given string or number to an integer. If the string or number can not convert as an integer, the error ValueError: Invalid literal for int() with base 10: ” will be thrown. The int() function returns an integer object created from a string or number. The python ValueError: Invalid literal for int() with base 10: ” error occurs when the built-in int() function is called with a string argument which cannot be parsed as an integer.
