Noob questions about Python
horpner at yahoo.com
Wed Oct 17 22:36:21 CEST 2007
On 2007-10-17, Bruno Desthuilliers
<bdesth.quelquechose at free.quelquepart.fr> wrote:
> Ixiaus a écrit :
>> val = 00110
>> as the integer 72 instead of returning 00110, why does Python
>> do that?
> Literal integers starting with '0' (zero) are treated as octal.
> It's a pretty common convention (like 0x for hexa). FWIW, PHP
> does just the same thing.
>> (and how can I get around it?)
> You can't. Python has no literal notation for binary integers
> so far. Literal notation for binary ints is not a common
> feature anyway.
You can obtain a practical workaround using the int built-in
>>> int('110', 2)
More information about the Python-list