From 31e1aec6f4faa0a07abf2ba6dfcf2ce5766ac7d6 Mon Sep 17 00:00:00 2001 From: Hanan Basheer <20b030018@iitb.ac.in> Date: Tue, 24 Aug 2021 14:28:10 +0530 Subject: [PATCH 1/2] Update introduction.rst --- Doc/tutorial/introduction.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst index 8763626ef553b98..edf4b1df6b7a10a 100644 --- a/Doc/tutorial/introduction.rst +++ b/Doc/tutorial/introduction.rst @@ -182,6 +182,29 @@ the first quote:: >>> print(r'C:\some\name') # note the r before the quote C:\some\name +There is one subtle aspect to raw strings that is of special concern to Windows +programmers: a raw string may not end in an odd number of ``\`` characters. +This is because the interpreter sees this as an escaped quote character, and so +it does not recognize it as the end of the string:: + + >>> fn = r'C:\this\will\not\work\' + File "", line 1 + fn = r'C:\this\will\not\work\' + ^ + SyntaxError: EOL while scanning string literal + +There are several workarounds for this. One is to use regular strings and +double the backslashes:: + + >>> fn = 'C:\\this\\will\\work\\' + +Another is to add a blank character before the quote and then remove it:: + + >>> fn = r'C:\this\will\work\ '.strip() + +Strings can be concatenated (glued together) with the ``+`` operator, and + repeated with ``*``:: + String literals can span multiple lines. One way is using triple-quotes: ``"""..."""`` or ``'''...'''``. End of lines are automatically included in the string, but it's possible to prevent this by adding a ``\`` at From 826e2b066a7426574dea3c7418047141151d097c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 26 Aug 2021 16:53:22 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Documentation/2021-08-26-16-53-22.bpo-11479.zHAOnZ.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Documentation/2021-08-26-16-53-22.bpo-11479.zHAOnZ.rst diff --git a/Misc/NEWS.d/next/Documentation/2021-08-26-16-53-22.bpo-11479.zHAOnZ.rst b/Misc/NEWS.d/next/Documentation/2021-08-26-16-53-22.bpo-11479.zHAOnZ.rst new file mode 100644 index 000000000000000..1e10c89d2522d79 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2021-08-26-16-53-22.bpo-11479.zHAOnZ.rst @@ -0,0 +1 @@ +Added a discussion of trailing backslash in raw string to tutorial \ No newline at end of file