String backslash characters

Leif K-Brooks eurleif at ecritters.biz
Fri Dec 24 03:02:52 EST 2004


PD wrote:
> Hello,
> 
> I am new to python, but i am quite curious about the following.
> 
> suppose you had
> 
> print '\378'
> 
> which should not work because \377 is the max. then it displays two
> characters (an 8 and a heart in my case...). What else does'nt quite
> make sense is that if this is an octal why is an 8 accepted?

It's not doing quite what you think. The '\37' is seen as octal, but 
since '8' isn't a valid octal digit, it's seen as the literal character '8'.

In other words, these two lines are equivalent:
 >>> '\378'
'\x1f8'
 >>> '\37' + '8'
'\x1f8'



More information about the Python-list mailing list