Suggestion to improve docs about nested quotes in strings

Dear team,

I hope this input finds you well. I recently reviewed the official documentation for the topic " [To quote a quote, we need to “escape” it, by preceding it with \ . Alternatively, we can use the other type of quotation marks]", and I noticed an error that I believe needs attention. As a dedicated user of this website, I value accurate and reliable information, and I believe addressing this issue will enhance the overall user experience.

The error I encountered is related to " [To quote a quote, we need to “escape” it, by preceding it with \ . Alternatively, we can use the other type of quotation marks]". Here are my suggestions for improvement:

‘doesn't’ # use ' to escape the single quote…
Website Output: “doesn’t”
Actual Output according to me: ‘doesn’t’
“doesn’t” # …or use double quotes instead
Website Output: “doesn’t”
Actual Output according to me: ‘doesn’t’

I recommend involving the documentation team to review and rectify these points. By doing so, we can enhance the quality and reliability of our documentation, benefiting both new and existing users.

Thank you for your attention to this matter. If you need further details or have any questions, feel free to reach out.

Thanks & Regards,
Saurabh Agarwal
Email: saurabhagarwal.ece@gmail.com
Code

Those aren’t apostrophes, those are other quotation characters:

'\u2018' LEFT SINGLE QUOTATION MARK
'd' LATIN SMALL LETTER D
'o' LATIN SMALL LETTER O
'e' LATIN SMALL LETTER E
's' LATIN SMALL LETTER S
'n' LATIN SMALL LETTER N
'\u2019' RIGHT SINGLE QUOTATION MARK
't' LATIN SMALL LETTER T
'\u2019' RIGHT SINGLE QUOTATION MARK

The documentation is correct if you use actual apostrophes.

Please see attached snap… :slight_smile:

I use "doesn't" that avoids the need for a \.

Could you provide a link to the section of the page of the docs you’re referring to? It would be easier for people to see what the issue is by looking at the current output.

You might want to review the formatting of your original post though, it’s a bit hard to read and I’m not sure if that was the intended formatting. You can use standard Markdown to format it.

The section in question is here: 3. An Informal Introduction to Python — Python 3.12.4 documentation

It looks like this in my browser, which looks correct to me.

This is how the examples look in my Python prompt:

Here are my suggestions for improvement:

It looks like you are using a notebook environment like Google Colab. I can confirm that it outputs the string as you show:

image

Personally I think it’s a bit unfortunate that Colab does this, and would write them a bug report.

We definitely want to make the docs as accurate and useful as possible, so thanks for making the suggestion. It’s difficult to anticipate all of the different execution environments and demonstrate them all. The Python prompt is what is provided with Python, and it shows a better output, so I would recommend keeping it.

8 Likes

The bug report to Collab would be along the lines of:

Collab’s repr for strings seems to use single quotes regardless of the presence of nested quote characters. It should match Python’s repr, which first chooses quotes that do not conflict, or otherwise outputs escape characters to disambiguate nested quotes.

10 Likes

Wow. That seems to have huge potential for error - I wonder how it’s not been flagged before release as it affects cut-n-paste from REPR to program, for example?

1 Like

Agreed. I’m not even sure why it’s being done - wouldn’t it be easier to just call on the normal repr function?

I wrote a bug report: Strings aren't shown with their usual repr() · Issue #4641 · googlecolab/colabtools · GitHub

5 Likes