Numeric literals in other than base 10 - was Annoying octal notation

Erik Max Francis max at alcyone.com
Mon Aug 24 10:12:22 CEST 2009


J. Cliff Dyer wrote:
> I had an objection to using spaces in numeric literals last time around
> and it still stands, and it still stands in the new one.
> 
> What happens if you use a literal like 0x10f 304?  Is 304 treated as
> decimal or hexadecimal?  It's not clear how you would begin to combine
> it.

Well, you can't combine them in any meaningful mathematical or 
computational sense if they're of different bases, so the answer lies 
therein:  You shouldn't be allowed to do that.

> The way string concatenation works, it takes two independent string
> literals, and combines them.  If you specify r'\n' 'abc\n', the first
> half is treated independently as a raw string, and the second half is
> treated as a normal string.  The result is '\\nabc\n'.
> 
> With numeric literals, this behavior doesn't even make sense.  How do
> you concatenate hex 10f with decimal 304?

You can't, and the operation makes no sense, which is what makes the 
syntax unambiguous.  An extended numeric literal continues the radix of 
wherever it started.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
   Do not seek death. Death will find you.
    -- Dag Hammarskjold



More information about the Python-list mailing list