[Python-checkins] CVS: python/dist/src/Doc/tut tut.tex,1.148,1.149
Fred L. Drake
fdrake@users.sourceforge.net
Thu, 06 Sep 2001 11:41:17 -0700
Update of /cvsroot/python/python/dist/src/Doc/tut
In directory usw-pr-cvs1:/tmp/cvs-serv30317/tut
Modified Files:
tut.tex
Log Message:
Clarified the interaction between string literals and continuation lines.
Fixes bug reported as SF bug #453728.
Index: tut.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.148
retrieving revision 1.149
diff -C2 -d -r1.148 -r1.149
*** tut.tex 2001/09/06 18:21:30 1.148
--- tut.tex 2001/09/06 18:41:15 1.149
***************
*** 527,532 ****
\end{verbatim}
! String literals can span multiple lines in several ways. Newlines can
! be escaped with backslashes:
\begin{verbatim}
--- 527,533 ----
\end{verbatim}
! String literals can span multiple lines in several ways. Continuation
! lines can be used, with a backslash as the last character on the line
! indicating that the next line is a logical continuation of the line:
\begin{verbatim}
***************
*** 534,542 ****
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
! significant.\n"
print hello
\end{verbatim}
! which would print the following:
\begin{verbatim}
--- 535,546 ----
several lines of text just as you would do in C.\n\
Note that whitespace at the beginning of the line is\
! significant."
!
print hello
\end{verbatim}
! Note that newlines would still need to be embedded in the string using
! \code{\e n}; the newline following the trailing backslash is
! discarded. This example would print the following:
\begin{verbatim}
***************
*** 546,551 ****
\end{verbatim}
Or, strings can be surrounded in a pair of matching triple-quotes:
! \code{"""} or \code {'''}. End of lines do not need to be escaped
when using triple-quotes, but they will be included in the string.
--- 550,574 ----
\end{verbatim}
+ If we make the string literal a ``raw'' string, however, the
+ \code{\e n} sequences are not converted to newlines, but the backslash
+ at the end of the line, and the newline character in the source, are
+ both included in the string as data. Thus, the example:
+
+ \begin{verbatim}
+ hello = r"This is a rather long string containing\n\
+ several lines of text much as you would do in C."
+
+ print hello
+ \end{verbatim}
+
+ would print:
+
+ \begin{verbatim}
+ This is a rather long string containing\n\
+ several lines of text much as you would do in C.
+ \end{verbatim}
+
Or, strings can be surrounded in a pair of matching triple-quotes:
! \code{"""} or \code{'\code{'}'}. End of lines do not need to be escaped
when using triple-quotes, but they will be included in the string.