osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strings: double versus single quotes


Greetings,

Nice idea

>>> '''You said "No it doesn't"'''
'You said "No it doesn\'t"'

Kind Regards,

Abdur-Rahmaan Janhangeer
compileralchemy <https://compileralchemy.github.io/> | blog
<https://abdur-rahmaanj.github.io/>
github <https://github.com/Abdur-RahmaanJ>
Mauritius


On Sun, May 24, 2020 at 9:05 AM Manfred Lotz <ml_news at posteo.de> wrote:

> 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
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>