Escaping the semicolon?
Diez B. Roggisch
deets at nospam.web.de
Tue Dec 4 11:03:42 EST 2007
Nick wrote:
> Hi all,
>
> Is this expected behavior?
>
>>>> s = '123;abc'
>>>> s.replace(';', '\;')
> '123\\;abc'
>
> I just wanted a single backslash. I can see why this probably happens
> but i wondered if it is definitely intentional.
There is only a single backslash. But the interactive prompt will use the
repr()-function to print out returned values. Which will for strings print
their escaped syntax.
Try the above with a
print s.replace(...)
and you will see your desired outcome.
diez
More information about the Python-list
mailing list