This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Leading “0” allowed, only for decimal zero
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.6, Python 3.2, Python 3.3, Python 3.4, Python 3.5
Status: closed Resolution: duplicate
Dependencies: Superseder: Deprecate 00000 as a synonym for 0
View: 24668
Assigned To: Nosy List: bignose, ethan.furman, steven.daprano
Priority: normal Keywords:

Created on 2016-03-05 23:58 by bignose, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg261227 - (view) Author: Ben Finney (bignose) Date: 2016-03-05 23:58
The language reference carves out a special case for decimal zero literals: they may have leading “0” digits. Non-zero decimal literals may not. This is apparently deliberate:

    Note that leading zeros in a non-zero decimal number are not allowed. This is for disambiguation with C-style octal literals, which Python used before version 3.0.


But the expressed rationale (“for disambiguation with C-style octal literals”) does not explain making decimal zero special compared with non-zero.

Is there a good reason for this inconsistency::

    0000    # valid syntax for zero literal
    0003    # SyntaxError
    0123    # SyntaxError

To my reading, they should all cause SyntaxError. What is the rationale for the special case of the first one?
msg261229 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2016-03-06 05:30
This was raised and rejected here:
msg261230 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-03-06 05:52
Short answer:  rationale unknown, but any number of zeroes is still unambiguously zero.

Closing as duplicate.
msg261231 - (view) Author: Ben Finney (bignose) Date: 2016-03-06 06:26
> rationale unknown

That's quite a pity. The inconsistency catches people out, and the docs do not make clear why an exception is made.

> but any number of zeroes is still unambiguously zero.

Of course. But the same is true for “0003 is unambiguously three”, yet that's invalid syntax.

I won't contest closing this report. But the above is not an explanation for the inconsistency.
Date User Action Args
2022-04-11 14:58:28adminsetgithub: 70677
2016-03-06 10:36:57berker.peksagsetsuperseder: Deprecate 00000 as a synonym for 0
2016-03-06 06:26:04bignosesetmessages: + msg261231
2016-03-06 05:52:50ethan.furmansetstatus: open -> closed

nosy: + ethan.furman
messages: + msg261230

resolution: duplicate
stage: resolved
2016-03-06 05:30:53steven.dapranosetnosy: + steven.daprano
messages: + msg261229
2016-03-05 23:58:36bignosecreate