# Numeric literal syntax

Cliff jcd at sdf.lonestar.org
Wed Sep 3 18:00:55 CEST 2008

On Sep 2, 12:34 am, Fredrik Lundh <fred... at pythonware.com> wrote:
> Ben Finney wrote:
> > I would argue that the precedent, already within Python, for using a
> > space to separate pieces of a string literal, is more important than
> > precedents from other programming languages.
>
> that precedent also tells us that the whitespace approach is a common
> source of errors.  taking an approach that's known to be error-prone and
> applying it to more cases isn't necessarily a great way to build a
> better language.
>
> </F>

Also a source of mental complexity.  The two proposals (whitespace vs.
underscores) are not just a question of what character to use, it's a
question of whether to create an integer (and possibly other numeric
type) literal that allows delimiters, or to allow separate literals to
be concatenated.  In the second case, which of the following would be
proper syntax?

0b1001 0110
0b1001 0b0110

In the first case, the second literal, on its own, is an octal
literal, but we expect it to behave as a binary literal.  In the
second case, we have more consistency with string literals (with which
you can do this: "abc" r'''\def''') but we lose the clarity of using
the concatenation to make the whole number more readable.

On the other hand, 0b1001_0110 has one clear meaning.  It is one
literal that stands alone.  I'm not super thrilled about the look (or
keyboard location) of the underscore, but it's better than anything
else that is available, and works within a single numeric literal.
For this reason I am +0 on the underscore and -1 on the space.