Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3.8: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers [duplicate]

With Python 3.8, is there a reason why 00 or 000000 are valid while 03 yields an error?

>>> 000
0

03
  File "<stdin>", line 1
    03
     ^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
like image 470
Philippe Remy Avatar asked Dec 06 '25 02:12

Philippe Remy


1 Answers

Yes. Python's constants derived from C, where integers starting with a 0 are interpreted in octal. So, 0377 has the decimal value 255. Over time, Python was changed to the 0o prefix, but C still allows the 0 prefix. To avoid any potential confusion, the 0 prefix is now a syntax error.

like image 89
Tim Roberts Avatar answered Dec 08 '25 15:12

Tim Roberts