backslashes and strings

Harald Kirsch kirschh at lionbioscience.com
Tue Apr 24 11:15:36 EDT 2001


Do I understand this correctly?

>>> x='\\\\s'
>>> x
'\\\\s'
>>> len(x)
3

After assignment x contains a string with 3 characters, in particular
2 backslashes and an `s'. Typing x and <RETURN> gives me a
representation of the value of x in a way that it could be parsed
again into the true value of x. Right?

Now continuing the example:

>>> eval('"'+x+'"')
'\\s'
>>> print eval('"'+x+'"')
\s
>>> print len(eval('"'+x+'"'))
2

This, in effect, runs the expression "\\s" which internally denotes a
string with two characters, namely a backslash and an `s'.


  Harald Kirsch

-- 
----------------+------------------------------------------------------
Harald Kirsch   | kirschh at lionbioscience.com | "How old is the epsilon?"
LION bioscience | +49 6221 4038 172          |        -- Paul Erdös
       *** Please do not send me copies of your posts. ***



More information about the Python-list mailing list