summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial/introduction.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/tutorial/introduction.rst')
-rw-r--r--Doc/tutorial/introduction.rst28
1 files changed, 24 insertions, 4 deletions
diff --git a/Doc/tutorial/introduction.rst b/Doc/tutorial/introduction.rst
index b279f71..8db19da 100644
--- a/Doc/tutorial/introduction.rst
+++ b/Doc/tutorial/introduction.rst
@@ -150,7 +150,6 @@ convert a complex number to a real number. Use ``abs(z)`` to get its magnitude
4.0
>>> abs(a) # sqrt(a.real**2 + a.imag**2)
5.0
- >>>
In interactive mode, the last printed expression is assigned to the variable
``_``. This means that when you are using Python as a desk calculator, it is
@@ -164,7 +163,6 @@ somewhat easier to continue calculations, for example::
113.0625
>>> round(_, 2)
113.06
- >>>
This variable should be treated as read-only by the user. Don't explicitly
assign a value to it --- you would create an independent local variable with the
@@ -212,12 +210,32 @@ next line is a logical continuation of the line::
Note that newlines still need to be embedded in the string using ``\n``; the
newline following the trailing backslash is discarded. This example would print
-the following::
+the following:
+
+.. code-block:: text
This is a rather long string containing
several lines of text just as you would do in C.
Note that whitespace at the beginning of the line is significant.
+Or, strings can be surrounded in a pair of matching triple-quotes: ``"""`` or
+``'''``. End of lines do not need to be escaped when using triple-quotes, but
+they will be included in the string. ::
+
+ print """
+ Usage: thingy [OPTIONS]
+ -h Display this usage message
+ -H hostname Hostname to connect to
+ """
+
+produces the following output:
+
+.. code-block:: text
+
+ Usage: thingy [OPTIONS]
+ -h Display this usage message
+ -H hostname Hostname to connect to
+
If we make the string literal a "raw" string, ``\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::
@@ -227,7 +245,9 @@ in the source, are both included in the string as data. Thus, the example::
print(hello)
-would print::
+would print:
+
+.. code-block:: text
This is a rather long string containing\n\
several lines of text much as you would do in C.