This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tutorial error in 3.1.2 Strings
Type: Stage:
Components: Documentation Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: nnorwitz, otan
Priority: normal Keywords:

Created on 2007-06-17 20:11 by otan, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg32357 - (view) Author: otan (otan) Date: 2007-06-17 20:11
The backslash is removed by the interpreter in this context:
>>> '"Isn\'t," she said.'
'"Isn\'t," she said.'

correct is:
>>> '"Isn\'t," she said.'
'"Isn't," she said.'

This might be confusing especially for beginners!
msg32358 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-06-18 02:53
This is correct in context.  If it was printed (ie, the str()), it would be correct to remove the backslash.  In this case it's taking the repr(), so the backslash must be in there.

>>> '"Isn\'t," she said.'
'"Isn\'t," she said.'
>>> print '"Isn\'t," she said.'
"Isn't," she said.

Or more specifically:

>>> print repr('"Isn\'t," she said.')
'"Isn\'t," she said.'
>>> print str('"Isn\'t," she said.')
"Isn't," she said.

I only wish I had noticed there wasn't a print before checking in a "fix". :-)
History
Date User Action Args
2022-04-11 14:56:25adminsetgithub: 45103
2007-06-17 20:11:11otancreate