Write Python. Understand every error.

Open the editor

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.

Try this code in Py-CRAFT

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

Learn the ideas behind it

Other common errors

Share this page: