the print statement

mirandacascade at yahoo.com mirandacascade at yahoo.com
Sat May 6 17:21:21 EDT 2006


O/S: Win2K
Vsn of Python: 2.4

Here is copy/paste from interactive window of pythonwin:

>>> x = "Joe's desk"
>>> y = 'Joe\x92s desk'
>>> type(x)
<type 'str'>
>>> type(y)
<type 'str'>
>>> print x
Joe's desk
>>> print y
Joe's desk
>>> if x == y:
... 	print 'equal'
... else:
... 	print 'not equal'
...
not equal
>>> len(x)
10
>>> len(y)
10
>>> ord(x[3])
39
>>> ord(y[3])
146
>>>

My questions are:
1) is the 'x' character within the variable y a signal that what
follows is a hex value?
2) is it more than just a coincidence that 146 (the result of
ord(y[3])) is the decimal equivalent of the hex number 92?
3) is there any character set in which 146 represents the
single-quote/apostrophe character? if so, which character set?
4) what is the role/function of the backslash character in the variable
y?
5) how did the print statement know to transform the contents of y
('Joe\x92s desk') to something that gets displayed as:

Joe's desk

?

6) Would it be correct to infer that the print statement is aware of
characters beyond the 128 characters in the ascii character set?




More information about the Python-list mailing list