literal numbers

Dan Bishop danb_83 at
Sat Jul 24 04:18:00 CEST 2004

Willem Broekema <news at> wrote in message news:<qqWdnThBC-nI4ZzcRVn-pQ at>...
> To me, it seems there are some irregularities in how literal numbers are 
> interpreted.
> As you know, Python allows integer literals in three bases:
> Now for complex integers:
>     "11j" -> 11j
>    "011j" -> 11j          <--
>   "0x11j" -> syntax error <--

The same occurs with real floating-point literals

  "11." -> 11.0
 "011." -> 11.0
"0x11." -> 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:
> 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?

I think the best solution would be to use some other syntax for octal
literals.  Even without the float and complex weirdness, it's not at
all obvious (except to C programmers) that 011 != 11.

More information about the Python-list mailing list