Occurs when trying to convert a non-numeric string into an integer.
value = "abc"
number = int(value)Traceback (most recent call last):
File "reproduce.py", line 2, in <module>
number = int(value)
ValueError: invalid literal for int() with base 10: 'abc'
value = "123"
if value.isdigit():
number = int(value)
print(number)123
The string "abc" cannot be converted to an integer. Check if the string contains only digits before using int().