Python Forum

Full Version: Question: print issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ask a silly question:

Why I got SyntaxError for print(1,012,000) but not print(1,000,000)?

See attached screenshot.
If you had used Python 3.10 then would have gotten Better error messages
So it i run it on Python 3.10.5,no need to search for an answer as the hint is in error message.
>>> print(1,012,000)
  File "<interactive input>", line 1
    print(1,012,000)
            ^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers

>>> print(1,0o12,000)
1 10 0
>>> 
>>> print(1,000,000)
1 0 0
Interesting that 000 does not have leading zeros.
Wild guess here, but I bet you wanted it to print 1,012,000. As in a million twelve thousand. In that case, you need to ditch the commas.