In the example below, an attempt is made to pass an empty string to the build in long() function. If the build in long() function is called with a string argument that contains an empty string, or contains a value other than a long, or contains a float value, this error can be reproduced. ValueError: invalid literal for long() with base 10: '' Traceback (most recent call last):įile "/Users/python/Desktop/test.py", line 2, in The stack trace shows the line that the long() build in function fails to parse to convert a long from a string or a number. The error ValueError: Invalid literal for long() with base 10: will be shown as below the stack trace. The long() build in function displays the error message that shows you the exact string you were trying to parse as a long. The long() function converts the string to a long if the string is a valid representation of the long and validates against the base value if specified (default is base 10). If the string is empty or contains a value other than a long number, or if the string contains a float, the error ValueError: Invalid literal for long() with base 10: will be thrown. The digits are supposed to be between 0 and 9. The default base for the long() buit-in function is 10. The long() function converts the given string or number to an integer. If the string or number can not convert as a long, the error ValueError: Invalid literal for long() with base 10: will be thrown.
![valueerror: invalid literal for int() with base 10: valueerror: invalid literal for int() with base 10:](https://user-images.githubusercontent.com/7622007/50743367-af8c3b80-121f-11e9-9639-e82ab14d27cc.png)
The int() function returns a long object created from a string or number. The python error ValueError: Invalid literal for long() with base 10: occurs when the built-in long() function is called with a string argument which cannot be parsed as a long.