On 14/6/2013 10:36 πμ, Antoon Pardon wrote:
Op 13-06-13 10:08, Νικόλαος Κούρας schreef:
On 13/6/2013 10:58 πμ, Chris Angelico wrote:
On Thu, Jun 13, 2013 at 5:42 PM, �������� ������
<supp...@superhost.gr> wrote:
On 13/6/2013 10:11 ��, Steven D'Aprano wrote:
No! That creates a string from 16474 in base two:
'0b100000001011010'

I disagree here.
16474 is a number in base 10. Doing bin(16474) we get the binary
representation of number 16474 and not a string.
Why you say we receive a string while python presents a binary number?

You can disagree all you like. Steven cited a simple point of fact,
one which can be verified in any Python interpreter. Nikos, you are
flat wrong here; bin(16474) creates a string.

Indeed python embraced it in single quoting '0b100000001011010' and
not as 0b100000001011010 which in fact makes it a string.

But since bin(16474) seems to create a string rather than an expected
number(at leat into my mind) then how do we get the binary
representation of the number 16474 as a number?

You don't. You should remember that python (or any programming language)
doesn't print numbers. It always prints string representations of
numbers. It is just so that we are so used to the decimal representation
that we think of that representation as being the number.

Normally that is not a problem but it can cause confusion when you are
working with mulitple representations.
Hold on!
Youa re basically saying here that:


>>> 16474
16474

is nto a number as we think but instead is string representation of a number?

I dont think so, if it were a string representation of a number that would print the following:

>>> 16474
'16474'

Python prints numbers:

>>> 16474
16474
>>> 0b100000001011010
16474
>>> 0x405a
16474

it prints them all to decimal format though.
but when we need a decimal integer to be turned into bin() or hex() we can bin(number) hex(number) and just remove the pair of single quoting.

--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to