Integers with leading zeroes

INADA Naoki songofacandy at gmail.com
Wed Jul 22 12:15:11 CEST 2015


Permitting leading 0s may make it harder to port Python 2 projects to
Python 3.

010 == 8 (Python 2)
010 == 10 (Python 3.x)

SyntaxError is very important for porting code.
So I'm -1 on permitting leading 0s for decimal numbers.


I think original question is for leading 0s for only 0.
Not for arbitrarily decimals.


On Wed, Jul 22, 2015 at 2:21 AM, Antoon Pardon <antoon.pardon at rece.vub.ac.be
> wrote:

> On 07/19/2015 07:39 AM, Steven D'Aprano 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.
> >
> > Does anyone use that (mis)feature?
> >
>
> Yes. I like to sometime write numbers with leading zeros.
> Sometimes these numbers represent codeblocks of a fixed
> number of digits. Always writing those numbers with this
> number of digits helps being aware of this. It is also
> easier for when you need to know how many leading zero's
> such a number has.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
INADA Naoki  <songofacandy at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150722/bb6c551b/attachment.html>


More information about the Python-list mailing list