How do I express a backslash in a string?

Frederick Polgardy sentientholon at gmail.com
Wed Aug 22 14:27:07 EDT 2007


On Aug 22, 1:19 pm, Tobiah <t... at tobiah.org> wrote:
> >>> "'"
> "'"
> >>> "\'"
> "'"
> >>> "\\'"
> "\\'"
> >>> "\\\'"
> "\\'"
>
> This is quite different than any other language
> that I am used to.  Normally, a double backslash
> takes away the special meaning of the last backslash,
> and so you are left with a single backslash.
>
> How do I express the single backslash?
>
> Thanks,
>
> Tobiah

It IS a single backslash - the interpreter in interactive mode
displays the string literal (escaped) version of what you entered,
which is, well, what you entered.  If you print it instead, you'll see
the actual string value.

>>> '\\'
'\\'
>>> print '\\'
\

Fred




More information about the Python-list mailing list