Why Python don't accept 03 as a number?

Chris Angelico rosuav at gmail.com
Fri Dec 7 22:13:51 EST 2018


On Sat, Dec 8, 2018 at 1:46 PM <jfong at ms4.hinet.net> wrote:
>
> MRAB at 2018/12/8 UTC+8 AM10:04:51 wrote:
> > Before Python 3, a leading 0 in an integer literal would indicate an
> > octal (base 8) number.
>
> So, the reason is historical.
>
> > The old form is now invalid in order to reduce the chance of bugs.
>
> I encounter this problem on trying to do something like this:
>     eval('03 + 00 + 15')
> It takes me some efforts to get rid of those leading zeros:-(
>
> Hope someday 03 can be accepted as a valid decimal number in Python 3.
>

Definitely not. What happens to all the code that used to be legal and
meant octal, and would become legal again but with a different
meaning? It'd be bad enough to have Python interpret something in a
way that's subtly different from the way other languages do (annoying,
but livable), but to do that across versions of the language would be
an incredibly bad idea.

ChrisA


More information about the Python-list mailing list