Strings: double versus single quotes
Manfred Lotz
ml_news at posteo.de
Sun May 24 00:41:19 EDT 2020
On Sat, 23 May 2020 14:46:04 -0400
Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Sat, 23 May 2020 11:03:09 -0500, Tim Chase
> <python.list at tim.thechases.com> declaimed the following:
>
>
> >
> >But when a string contains both, it biases towards single quotes:
> >
> > >>> "You said \"No it doesn't\""
> > 'You said "No it doesn\'t"'
>
> This is where using triple quotes (or triple apostrophes)
> around the entire thing simplifies it all... (except for a need to
> separate the four ending quotes)
Exactly, I also would opt for triple quotes in this case.
>
> >>> """You said "No it doesn't" """
> 'You said "No it doesn\'t" '
> >>> '''You said "No it doesn't"'''
> 'You said "No it doesn\'t"'
> >>>
>
> NO \ escapes needed on the input strings.
>
> >>> print("""You said "No it doesn't" """)
> You said "No it doesn't"
> >>> print('''You said "No it doesn't"''')
> You said "No it doesn't"
> >>>
>
>
--
Manfred
More information about the Python-list
mailing list