literal numbers

Willem Broekema news at pastelhorn.com
Fri Jul 23 17:00:02 EDT 2004


To me, it seems there are some irregularities in how literal numbers are 
interpreted.

As you know, Python allows integer literals in three bases:
    "11" -> (decimal) 11
   "011" -> octal 11 = 9
  "0x11" -> hex 11 = 17


Now for complex integers:
    "11j" -> 11j
   "011j" -> 11j          <--
  "0x11j" -> syntax error <--

I expected "011j" to be read as an octal complex, resulting in 9j,
and "0x11j" to be read as a hexadecimal complex, resulting in 17j.

Currently, "011j" and "011 * 1j" are different, and that strikes me as 
wrong:

 >>> 011
9
 >>> 011j
11j
 >>> 011 * 1j
9j


(Complex) Floats:
     "11.3" -> 11.3
    "11.3j" -> 11.3j

    "011.3" -> 11.3   <--
   "011.3j" -> 11.3j  <--

   "0x11.3" -> syntax error
  "0x11.3j" -> syntax error

So "011.3" and "011.3j" are read as in base 10. Wouldn't a syntax error 
be more appropriate, as it is an attempt to read a floating point in 
octal, which is unsupported?


- Willem



More information about the Python-list mailing list