[Tutor] String replace question
python at mhockey.us
Wed Jul 28 14:59:58 CEST 2010
>>>> print uri.replace('.', '\.')
> and you'll find the replacement works fine.
> Or write the output to file, and look at the file.
> Python shows a representation on its prompt, and thus needs to escape the backslash (by prepending another backslash). Otherwise you might think '\.' was meant, which is simply a '.'.
> But consider:
>>>> uri.replace('.', '\n')
>>>> print uri.replace('.', '\n')
> because '\n' is really a different string (character) than a backslash + 'n'.
Thanks, that was very helpful. I was using the interactive interpreter
to test things.
More information about the Tutor