Python
ValueError: invalid literal for int()
ValueError
A function received a value of the right type but with invalid content (e.g., int('abc')).
Common Causes
- Parsing invalid string to int/float
- Empty or malformed input
- Wrong format passed to built-in
Fixes
- 1. Validate before converting
s = input().strip() if s.isdigit(): n = int(s) - 2. Use try/except
try: n = int(s) except ValueError: n = default - 3. Handle empty input
n = int(s) if s else 0
Still not fixed?
- • Search the exact error message on Stack Overflow or GitHub Issues
- • Check the official docs for the language or tool
- • Ensure your versions (Node, Python, npm, Docker) are up to date
- • Try in a minimal reproduction (new project, single file)
Related Errors
DuskTools That Might Help
All Errors
JavaScript Heap Out of MemoryModuleNotFoundErrorAddress Already in UseIndentationErrorCannot Find ModulePeer Dependency WarningCORS Policy BlockedTypeError: 'NoneType' Not SubscriptableMerge ConflictDocker Port Already AllocatedENOENT: No Such File or DirectoryKeyErrorMaxListenersExceededWarningRecursionErrorDetached HEAD StateEACCES: Permission DeniedNo Space Left on DeviceERR_REQUIRE_ESMFileNotFoundError