[Tutor] Concatenating string
bob gailer
bgailer at gmail.com
Tue Feb 22 15:15:24 CET 2011
On 2/22/2011 8:46 AM, tee chwee liong wrote:
> hi,
>
> >>> bin(0xff0)
> '111111110000'
> >>> bin(0xff1)
> '111111110001'
> >>> a=bin(0xff0)+bin(0xff1)
> >>> a
> '111111110000111111110001'
> >>> b=0xff0
> >>> c=0xff1
> >>> d=b+c
> >>> d
> 8161
> >>> bin(d)
> '1111111100001'
>
> question:
> 1) why is it that a and d values are different? i'm using Python 2.5.
Why would you expect otherwise?
What are the types of a and d? They are not the same type; therefore you
get different results.
How do you determine the type of an object?
1 - Use the type() function.
2 - notice '' around a and not around d
3 - Read the documentation:
bin(/x/) Convert an integer number to a binary string. The
documentation is weak here, but at least it tells you that the result is
a string.
0x is covered under (at least for Python 2.6) in 2.4.4. Integer and long
integer literals.
--
Bob Gailer
919-636-4239
Chapel Hill NC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110222/5864f21c/attachment.html>
More information about the Tutor
mailing list