Error guide · SyntaxError
SyntaxError: invalid decimal literal
A name was written starting with a digit.
Example
2nd_place = "Asha"
What Python says
SyntaxError: invalid decimal literal
As printed by Python 3.12. Other versions may word it slightly differently.
Why it happens
Variable names must start with a letter or an underscore. Python reads 2nd_place as the number 2 followed by letters, which makes no sense. After the first character, digits are fine, so place2 is a good name.
How to fix it
second_place = "Asha" print(second_place)
Output: Asha
Tips
- Start names with a letter:
second_placeorplace_2nd. - Names cannot contain spaces or symbols such as
-. Use underscores. - Keywords such as
classandforcannot be used as names either.