Integers with leading zeroes
Ian Kelly
ian.g.kelly at gmail.com
Sun Jul 19 01:46:08 EDT 2015
On Sat, Jul 18, 2015 at 11:39 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> In Python 2, integer literals with leading zeroes are treated as octal, so
> 09 is a syntax error and 010 is 8.
>
> This is confusing to those not raised on C-style octal literals, so in
> Python 3 leading zeroes are prohibited in int literals. Octal is instead
> written using the prefix 0o, similar to hex 0x and binary 0b.
>
> Consequently Python 3 makes both 09 and 010 a syntax error.
>
> However there is one exception: zero itself is allowed any number of leading
> zeroes, so 00000 is a legal way to write zero as a base-10 int literal.
It's obviously a base-8 literal, not a base-10 literal. :-P
> Does anyone use that (mis)feature?
I don't, but why should it matter?
More information about the Python-list
mailing list