faqts : Computers : Programming : Languages : Python : Common Problems : Strings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 20 people (25%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

Why is ['\x00'+'\x31'] converted into ['\x001] ?

Dec 30th, 2002 23:28
Lin Zhemin, Andreas Trawoeger,


Since python shows chr(0) as '\x00', you got the result. Try:
>>> chr(0)
'\x00'
>>> a=chr(0)+chr(0x31)
>>> a
'\x001'
>>> len(a)
2
You see '\x001' is combined actually by 2 letters.  You may give another
try:
>>> a='\x01'+'\x02'
>>> a
'\x01\x02'
>>> len(a)
2
Hope that helps you :)