On Thu, 13 Jun 2013 12:41:41 +0300, Νικόλαος Κούρας wrote:

>> In Python 2:
>>>>> 16474
> typing 16474 in interactive session both in python 2 and 3 gives back
> the number 16474
> 
> while we want the the binary representation of the number 16474

Python does not work that way. Ints *always* display in decimal. 
Regardless of whether you enter the decimal in binary:

py> 0b100000001011010
16474


octal:

py> 0o40132
16474


or hexadecimal:

py> 0x405A
16474


ints always display in decimal. The only way to display in another base 
is to build a string showing what the int would look like in a different 
base:

py> hex(16474)
'0x405a'

Notice that the return value of bin, oct and hex are all strings. If they 
were ints, then they would display in decimal, defeating the purpose!


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to