Python gotcha of the day

Cameron Simpson cs at cskk.id.au
Wed Mar 14 00:40:55 EDT 2018


On 14Mar2018 04:08, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
>Explain the difference between these two triple-quoted strings:
>
>Here is a triple-quoted string containing spaces and a triple-quote:
>
>py> """ \""" """
>' """ '
>
>
>But remove the spaces, and two of the quotation marks disappear:
>
>py> """\""""""
>'"'

"""\"""" ""

Implicit string concatenation of an empty string.

I confess I try to have my quote delimiters distinct from any embedded quotes 
to avoid wanting backslashes. It is conincidental that my habit tends to 
sidestep the above issue.

Cheers,
Cameron Simpson <cs at cskk.id.au> (formerly cs at zip.com.au)



More information about the Python-list mailing list