annotate Doc/ref/ref2.tex @ 21467:4e35fa5d5708 legacy-trunk

Add documentation for the help() built-in; contributed by Ka-Ping Yee. This is part of SF patch #494622.
author Fred Drake <fdrake@acm.org>
date Tue, 18 Dec 2001 16:31:08 +0000
parents d1f938eee700
children cc788b3b21b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8752
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
1 \chapter{Lexical analysis\label{lexical}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2
8337
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
3 A Python program is read by a \emph{parser}. Input to the parser is a
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
4 stream of \emph{tokens}, generated by the \emph{lexical analyzer}. This
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5 chapter describes how the lexical analyzer breaks a file into tokens.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 \index{lexical analysis}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7 \index{parser}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8 \index{token}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
10 Python uses the 7-bit \ASCII{} character set for program text and string
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
11 literals. 8-bit characters may be used in string literals and comments
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
12 but their interpretation is platform dependent; the proper way to
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
13 insert 8-bit characters in string literals is by using octal or
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
14 hexadecimal escape sequences.
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
15
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
16 The run-time character set depends on the I/O devices connected to the
21062
bc02c3b09626 Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents: 19621
diff changeset
17 program but is generally a superset of \ASCII.
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
18
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
19 \strong{Future compatibility note:} It may be tempting to assume that the
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
20 character set for 8-bit characters is ISO Latin-1 (an \ASCII{}
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
21 superset that covers most western languages that use the Latin
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
22 alphabet), but it is possible that in the future Unicode text editors
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
23 will become common. These generally use the UTF-8 encoding, which is
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
24 also an \ASCII{} superset, but with very different use for the
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
25 characters with ordinals 128-255. While there is no consensus on this
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
26 subject yet, it is unwise to assume either Latin-1 or UTF-8, even
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
27 though the current implementation appears to favor Latin-1. This
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
28 applies both to the source character set and the run-time character
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
29 set.
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
30
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
31
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
32 \section{Line structure\label{line-structure}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
34 A Python program is divided into a number of \emph{logical lines}.
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
35 \index{line structure}
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
36
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
37
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
38 \subsection{Logical lines\label{logical}}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
39
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
40 The end of
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
41 a logical line is represented by the token NEWLINE. Statements cannot
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 cross logical line boundaries except where NEWLINE is allowed by the
8736
6c20ca723180 e.g. -> e.g.,
Guido van Rossum <guido@python.org>
parents: 8508
diff changeset
43 syntax (e.g., between statements in compound statements).
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
44 A logical line is constructed from one or more \emph{physical lines}
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
45 by following the explicit or implicit \emph{line joining} rules.
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
46 \index{logical line}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
47 \index{physical line}
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
48 \index{line joining}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
49 \index{NEWLINE token}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
50
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
51
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
52 \subsection{Physical lines\label{physical}}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
53
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
54 A physical line ends in whatever the current platform's convention is
21062
bc02c3b09626 Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents: 19621
diff changeset
55 for terminating lines. On \UNIX, this is the \ASCII{} LF (linefeed)
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
56 character. On DOS/Windows, it is the \ASCII{} sequence CR LF (return
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
57 followed by linefeed). On Macintosh, it is the \ASCII{} CR (return)
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
58 character.
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
59
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
60
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
61 \subsection{Comments\label{comments}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
62
8337
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
63 A comment starts with a hash character (\code{\#}) that is not part of
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
64 a string literal, and ends at the end of the physical line. A comment
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
65 signifies the end of the logical line unless the implicit line joining
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
66 rules are invoked.
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
67 Comments are ignored by the syntax; they are not tokens.
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
68 \index{comment}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
69 \index{hash character}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
70
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
71
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
72 \subsection{Explicit line joining\label{explicit-joining}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
73
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
74 Two or more physical lines may be joined into logical lines using
8337
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
75 backslash characters (\code{\e}), as follows: when a physical line ends
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
76 in a backslash that is not part of a string literal or comment, it is
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
77 joined with the following forming a single logical line, deleting the
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
78 backslash and the following end-of-line character. For example:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
79 \index{physical line}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
80 \index{line joining}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
81 \index{line continuation}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
82 \index{backslash character}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
83 %
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
84 \begin{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
85 if 1900 < year < 2100 and 1 <= month <= 12 \
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
86 and 1 <= day <= 31 and 0 <= hour < 24 \
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
87 and 0 <= minute < 60 and 0 <= second < 60: # Looks like a valid date
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
88 return 1
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
89 \end{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
90
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
91 A line ending in a backslash cannot carry a comment. A backslash does
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
92 not continue a comment. A backslash does not continue a token except
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
93 for string literals (i.e., tokens other than string literals cannot be
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
94 split across physical lines using a backslash). A backslash is
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
95 illegal elsewhere on a line outside a string literal.
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
96
10258
163fd3d95c17 Revised description of blank line handling for the interpreter, based
Fred Drake <fdrake@acm.org>
parents: 9202
diff changeset
97
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
98 \subsection{Implicit line joining\label{implicit-joining}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
99
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
100 Expressions in parentheses, square brackets or curly braces can be
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
101 split over more than one physical line without using backslashes.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
102 For example:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
103
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
104 \begin{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
105 month_names = ['Januari', 'Februari', 'Maart', # These are the
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
106 'April', 'Mei', 'Juni', # Dutch names
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
107 'Juli', 'Augustus', 'September', # for the months
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
108 'Oktober', 'November', 'December'] # of the year
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
109 \end{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
110
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
111 Implicitly continued lines can carry comments. The indentation of the
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
112 continuation lines is not important. Blank continuation lines are
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
113 allowed. There is no NEWLINE token between implicit continuation
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
114 lines. Implicitly continued lines can also occur within triple-quoted
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
115 strings (see below); in that case they cannot carry comments.
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
116
10258
163fd3d95c17 Revised description of blank line handling for the interpreter, based
Fred Drake <fdrake@acm.org>
parents: 9202
diff changeset
117
163fd3d95c17 Revised description of blank line handling for the interpreter, based
Fred Drake <fdrake@acm.org>
parents: 9202
diff changeset
118 \subsection{Blank lines \index{blank line}\label{blank-lines}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
119
10258
163fd3d95c17 Revised description of blank line handling for the interpreter, based
Fred Drake <fdrake@acm.org>
parents: 9202
diff changeset
120 A logical line that contains only spaces, tabs, formfeeds and possibly
163fd3d95c17 Revised description of blank line handling for the interpreter, based
Fred Drake <fdrake@acm.org>
parents: 9202
diff changeset
121 a comment, is ignored (i.e., no NEWLINE token is generated). During
163fd3d95c17 Revised description of blank line handling for the interpreter, based
Fred Drake <fdrake@acm.org>
parents: 9202
diff changeset
122 interactive input of statements, handling of a blank line may differ
163fd3d95c17 Revised description of blank line handling for the interpreter, based
Fred Drake <fdrake@acm.org>
parents: 9202
diff changeset
123 depending on the implementation of the read-eval-print loop. In the
163fd3d95c17 Revised description of blank line handling for the interpreter, based
Fred Drake <fdrake@acm.org>
parents: 9202
diff changeset
124 standard implementation, an entirely blank logical line (i.e.\ one
163fd3d95c17 Revised description of blank line handling for the interpreter, based
Fred Drake <fdrake@acm.org>
parents: 9202
diff changeset
125 containing not even whitespace or a comment) terminates a multi-line
163fd3d95c17 Revised description of blank line handling for the interpreter, based
Fred Drake <fdrake@acm.org>
parents: 9202
diff changeset
126 statement.
163fd3d95c17 Revised description of blank line handling for the interpreter, based
Fred Drake <fdrake@acm.org>
parents: 9202
diff changeset
127
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
128
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
129 \subsection{Indentation\label{indentation}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
130
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
131 Leading whitespace (spaces and tabs) at the beginning of a logical
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
132 line is used to compute the indentation level of the line, which in
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
133 turn is used to determine the grouping of statements.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
134 \index{indentation}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
135 \index{whitespace}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
136 \index{leading whitespace}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
137 \index{space}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
138 \index{tab}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
139 \index{grouping}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
140 \index{statement grouping}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
141
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
142 First, tabs are replaced (from left to right) by one to eight spaces
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
143 such that the total number of characters up to and including the
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
144 replacement is a multiple of
21062
bc02c3b09626 Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents: 19621
diff changeset
145 eight (this is intended to be the same rule as used by \UNIX). The
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
146 total number of spaces preceding the first non-blank character then
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
147 determines the line's indentation. Indentation cannot be split over
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
148 multiple physical lines using backslashes; the whitespace up to the
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
149 first backslash determines the indentation.
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
150
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
151 \strong{Cross-platform compatibility note:} because of the nature of
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
152 text editors on non-UNIX platforms, it is unwise to use a mixture of
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
153 spaces and tabs for the indentation in a single source file.
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
154
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
155 A formfeed character may be present at the start of the line; it will
12217
5ea773413531 Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10356
diff changeset
156 be ignored for the indentation calculations above. Formfeed
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
157 characters occurring elsewhere in the leading whitespace have an
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
158 undefined effect (for instance, they may reset the space count to
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
159 zero).
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
160
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
161 The indentation levels of consecutive lines are used to generate
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
162 INDENT and DEDENT tokens, using a stack, as follows.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
163 \index{INDENT token}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
164 \index{DEDENT token}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
165
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
166 Before the first line of the file is read, a single zero is pushed on
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
167 the stack; this will never be popped off again. The numbers pushed on
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
168 the stack will always be strictly increasing from bottom to top. At
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
169 the beginning of each logical line, the line's indentation level is
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
170 compared to the top of the stack. If it is equal, nothing happens.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
171 If it is larger, it is pushed on the stack, and one INDENT token is
8337
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
172 generated. If it is smaller, it \emph{must} be one of the numbers
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
173 occurring on the stack; all numbers on the stack that are larger are
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
174 popped off, and for each number popped off a DEDENT token is
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
175 generated. At the end of the file, a DEDENT token is generated for
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
176 each number remaining on the stack that is larger than zero.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
177
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
178 Here is an example of a correctly (though confusingly) indented piece
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
179 of Python code:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
180
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
181 \begin{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
182 def perm(l):
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
183 # Compute the list of all permutations of l
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
184 if len(l) <= 1:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
185 return [l]
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
186 r = []
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
187 for i in range(len(l)):
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
188 s = l[:i] + l[i+1:]
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
189 p = perm(s)
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
190 for x in p:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
191 r.append(l[i:i+1] + x)
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
192 return r
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
193 \end{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
194
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
195 The following example shows various indentation errors:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
196
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
197 \begin{verbatim}
21345
d1f938eee700 Fix whitespace in example of bad indentation: a comment indicated that one
Fred Drake <fdrake@acm.org>
parents: 21198
diff changeset
198 def perm(l): # error: first line indented
d1f938eee700 Fix whitespace in example of bad indentation: a comment indicated that one
Fred Drake <fdrake@acm.org>
parents: 21198
diff changeset
199 for i in range(len(l)): # error: not indented
d1f938eee700 Fix whitespace in example of bad indentation: a comment indicated that one
Fred Drake <fdrake@acm.org>
parents: 21198
diff changeset
200 s = l[:i] + l[i+1:]
d1f938eee700 Fix whitespace in example of bad indentation: a comment indicated that one
Fred Drake <fdrake@acm.org>
parents: 21198
diff changeset
201 p = perm(l[:i] + l[i+1:]) # error: unexpected indent
d1f938eee700 Fix whitespace in example of bad indentation: a comment indicated that one
Fred Drake <fdrake@acm.org>
parents: 21198
diff changeset
202 for x in p:
d1f938eee700 Fix whitespace in example of bad indentation: a comment indicated that one
Fred Drake <fdrake@acm.org>
parents: 21198
diff changeset
203 r.append(l[i:i+1] + x)
d1f938eee700 Fix whitespace in example of bad indentation: a comment indicated that one
Fred Drake <fdrake@acm.org>
parents: 21198
diff changeset
204 return r # error: inconsistent dedent
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
205 \end{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
206
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
207 (Actually, the first three errors are detected by the parser; only the
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
208 last error is found by the lexical analyzer --- the indentation of
8337
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
209 \code{return r} does not match a level popped off the stack.)
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
210
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
211
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
212 \subsection{Whitespace between tokens\label{whitespace}}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
213
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
214 Except at the beginning of a logical line or in string literals, the
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
215 whitespace characters space, tab and formfeed can be used
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
216 interchangeably to separate tokens. Whitespace is needed between two
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
217 tokens only if their concatenation could otherwise be interpreted as a
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
218 different token (e.g., ab is one token, but a b is two tokens).
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
219
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
220
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
221 \section{Other tokens\label{other-tokens}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
222
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
223 Besides NEWLINE, INDENT and DEDENT, the following categories of tokens
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
224 exist: \emph{identifiers}, \emph{keywords}, \emph{literals},
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
225 \emph{operators}, and \emph{delimiters}.
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
226 Whitespace characters (other than line terminators, discussed earlier)
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
227 are not tokens, but serve to delimit tokens.
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
228 Where
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
229 ambiguity exists, a token comprises the longest possible string that
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
230 forms a legal token, when read from left to right.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
231
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
232
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
233 \section{Identifiers and keywords\label{identifiers}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
234
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
235 Identifiers (also referred to as \emph{names}) are described by the following
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
236 lexical definitions:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
237 \index{identifier}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
238 \index{name}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
239
18429
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
240 \begin{productionlist}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
241 \production{identifier}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
242 {(\token{letter}|"_") (\token{letter} | \token{digit} | "_")*}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
243 \production{letter}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
244 {\token{lowercase} | \token{uppercase}}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
245 \production{lowercase}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
246 {"a"..."z"}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
247 \production{uppercase}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
248 {"A"..."Z"}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
249 \production{digit}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
250 {"0"..."9"}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
251 \end{productionlist}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
252
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
253 Identifiers are unlimited in length. Case is significant.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
254
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
255
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
256 \subsection{Keywords\label{keywords}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
257
8337
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
258 The following identifiers are used as reserved words, or
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
259 \emph{keywords} of the language, and cannot be used as ordinary
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
260 identifiers. They must be spelled exactly as written here:%
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
261 \index{keyword}%
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
262 \index{reserved word}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
263
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
264 \begin{verbatim}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
265 and del for is raise
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
266 assert elif from lambda return
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
267 break else global not try
21198
f17a37de6285 Put the keywords back in alphabetical order. Apparently somebody
Guido van Rossum <guido@python.org>
parents: 21062
diff changeset
268 class except if or while
f17a37de6285 Put the keywords back in alphabetical order. Apparently somebody
Guido van Rossum <guido@python.org>
parents: 21062
diff changeset
269 continue exec import pass yield
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
270 def finally in print
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
271 \end{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
272
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
273 % When adding keywords, use reswords.py for reformatting
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
274
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
275
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
276 \subsection{Reserved classes of identifiers\label{id-classes}}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
277
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
278 Certain classes of identifiers (besides keywords) have special
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
279 meanings. These are:
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
280
10356
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
281 \begin{tableiii}{l|l|l}{code}{Form}{Meaning}{Notes}
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
282 \lineiii{_*}{Not imported by \samp{from \var{module} import *}}{(1)}
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
283 \lineiii{__*__}{System-defined name}{}
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
284 \lineiii{__*}{Class-private name mangling}{}
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
285 \end{tableiii}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
286
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
287 (XXX need section references here.)
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
288
10356
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
289 Note:
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
290
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
291 \begin{description}
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
292 \item[(1)] The special identifier \samp{_} is used in the interactive
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
293 interpreter to store the result of the last evaluation; it is stored
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
294 in the \module{__builtin__} module. When not in interactive mode,
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
295 \samp{_} has no special meaning and is not defined.
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
296 \end{description}
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
297
8923ad7e13f2 Added note about __builtin__._ to section dicussing classes of
Fred Drake <fdrake@acm.org>
parents: 10258
diff changeset
298
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
299 \section{Literals\label{literals}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
300
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
301 Literals are notations for constant values of some built-in types.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
302 \index{literal}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
303 \index{constant}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
304
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
305
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
306 \subsection{String literals\label{strings}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
307
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
308 String literals are described by the following lexical definitions:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
309 \index{string literal}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
310
21062
bc02c3b09626 Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents: 19621
diff changeset
311 \index{ASCII@\ASCII}
18429
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
312 \begin{productionlist}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
313 \production{stringliteral}
19257
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
314 {[\token{stringprefix}](\token{shortstring} | \token{longstring})}
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
315 \production{stringprefix}
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
316 {"r" | "u" | "ur" | "R" | "U" | "UR" | "Ur" | "uR"}
18429
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
317 \production{shortstring}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
318 {"'" \token{shortstringitem}* "'"
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
319 | '"' \token{shortstringitem}* '"'}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
320 \production{longstring}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
321 {"'''" \token{longstringitem}* "'''"
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
322 | '"""' \token{longstringitem}* '"""'}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
323 \production{shortstringitem}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
324 {\token{shortstringchar} | \token{escapeseq}}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
325 \production{longstringitem}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
326 {\token{longstringchar} | \token{escapeseq}}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
327 \production{shortstringchar}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
328 {<any ASCII character except "\e" or newline or the quote>}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
329 \production{longstringchar}
21345
d1f938eee700 Fix whitespace in example of bad indentation: a comment indicated that one
Fred Drake <fdrake@acm.org>
parents: 21198
diff changeset
330 {<any ASCII character except "\e">}
18429
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
331 \production{escapeseq}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
332 {"\e" <any ASCII character>}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
333 \end{productionlist}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
334
19257
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
335 One syntactic restriction not indicated by these productions is that
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
336 whitespace is not allowed between the \grammartoken{stringprefix} and
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
337 the rest of the string literal.
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
338
15619
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
339 \index{triple-quoted string}
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
340 \index{Unicode Consortium}
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
341 \index{string!Unicode}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
342 In plain English: String literals can be enclosed in matching single
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
343 quotes (\code{'}) or double quotes (\code{"}). They can also be
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
344 enclosed in matching groups of three single or double quotes (these
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
345 are generally referred to as \emph{triple-quoted strings}). The
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
346 backslash (\code{\e}) character is used to escape characters that
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
347 otherwise have a special meaning, such as newline, backslash itself,
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
348 or the quote character. String literals may optionally be prefixed
19257
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
349 with a letter `r' or `R'; such strings are called \dfn{raw
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
350 strings}\index{raw string} and use different rules for interpreting
15619
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
351 backslash escape sequences. A prefix of 'u' or 'U' makes the string
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
352 a Unicode string. Unicode strings use the Unicode character set as
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
353 defined by the Unicode Consortium and ISO~10646. Some additional
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
354 escape sequences, described below, are available in Unicode strings.
19257
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
355 The two prefix characters may be combined; in this case, `u' must
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
356 appear before `r'.
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
357
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
358 In triple-quoted strings,
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
359 unescaped newlines and quotes are allowed (and are retained), except
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
360 that three unescaped quotes in a row terminate the string. (A
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
361 ``quote'' is the character used to open the string, i.e. either
8337
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
362 \code{'} or \code{"}.)
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
363
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
364 Unless an `r' or `R' prefix is present, escape sequences in strings
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
365 are interpreted according to rules similar
18772
b10ff337896b Removed unnecessary section "Unicode literals"; all the discussion is
Fred Drake <fdrake@acm.org>
parents: 18768
diff changeset
366 to those used by Standard C. The recognized escape sequences are:
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
367 \index{physical line}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
368 \index{escape sequence}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
369 \index{Standard C}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
370 \index{C}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
371
8752
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
372 \begin{tableii}{l|l}{code}{Escape Sequence}{Meaning}
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
373 \lineii{\e\var{newline}} {Ignored}
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
374 \lineii{\e\e} {Backslash (\code{\e})}
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
375 \lineii{\e'} {Single quote (\code{'})}
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
376 \lineii{\e"} {Double quote (\code{"})}
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
377 \lineii{\e a} {\ASCII{} Bell (BEL)}
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
378 \lineii{\e b} {\ASCII{} Backspace (BS)}
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
379 \lineii{\e f} {\ASCII{} Formfeed (FF)}
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
380 \lineii{\e n} {\ASCII{} Linefeed (LF)}
15619
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
381 \lineii{\e N\{\var{name}\}}
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
382 {Character named \var{name} in the Unicode database (Unicode only)}
8752
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
383 \lineii{\e r} {\ASCII{} Carriage Return (CR)}
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
384 \lineii{\e t} {\ASCII{} Horizontal Tab (TAB)}
19257
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
385 \lineii{\e u\var{xxxx}} {Character with 16-bit hex value \var{xxxx} (Unicode only)}
1c39b96d29c3 Add material about the "r" and "u" prefixes for string literals; should
Fred Drake <fdrake@acm.org>
parents: 19054
diff changeset
386 \lineii{\e U\var{xxxxxxxx}}{Character with 32-bit hex value \var{xxxxxxxx} (Unicode only)}
8752
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
387 \lineii{\e v} {\ASCII{} Vertical Tab (VT)}
15619
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
388 \lineii{\e\var{ooo}} {\ASCII{} character with octal value \var{ooo}}
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
389 \lineii{\e x\var{hh}} {\ASCII{} character with hex value \var{hh}}
8752
4e05e38445ce Converted some {tabular}s to use {tablei*} environments.
Fred Drake <fdrake@acm.org>
parents: 8736
diff changeset
390 \end{tableii}
21062
bc02c3b09626 Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents: 19621
diff changeset
391 \index{ASCII@\ASCII}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
392
16591
df7d52ae20e4 Feeble attempt to repair obsolete info about hex escapes.
Tim Peters <tim.peters@gmail.com>
parents: 15776
diff changeset
393 As in Standard C, up to three octal digits are accepted. However,
df7d52ae20e4 Feeble attempt to repair obsolete info about hex escapes.
Tim Peters <tim.peters@gmail.com>
parents: 15776
diff changeset
394 exactly two hex digits are taken in hex escapes.
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
395
15619
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
396 Unlike Standard \index{unrecognized escape sequence}C,
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
397 all unrecognized escape sequences are left in the string unchanged,
15619
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
398 i.e., \emph{the backslash is left in the string}. (This behavior is
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
399 useful when debugging: if an escape sequence is mistyped, the
15619
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
400 resulting output is more easily recognized as broken.) It is also
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
401 important to note that the escape sequences marked as ``(Unicode
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
402 only)'' in the table above fall into the category of unrecognized
50d9b590627d Updated string literals description to encompass Unicode literals and the
Fred Drake <fdrake@acm.org>
parents: 15415
diff changeset
403 escapes for non-Unicode string literals.
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
404
15776
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
405 When an `r' or `R' prefix is present, a character following a
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
406 backslash is included in the string without change, and \emph{all
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
407 backslashes are left in the string}. For example, the string literal
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
408 \code{r"\e n"} consists of two characters: a backslash and a lowercase
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
409 `n'. String quotes can be escaped with a backslash, but the backslash
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
410 remains in the string; for example, \code{r"\e""} is a valid string
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
411 literal consisting of two characters: a backslash and a double quote;
18768
2e173da11d2d Fix typo in description of raw strings: "value" --> "valid"
Fred Drake <fdrake@acm.org>
parents: 18429
diff changeset
412 \code{r"\e"} is not a valid string literal (even a raw string cannot
15776
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
413 end in an odd number of backslashes). Specifically, \emph{a raw
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
414 string cannot end in a single backslash} (since the backslash would
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
415 escape the following quote character). Note also that a single
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
416 backslash followed by a newline is interpreted as those two characters
4370fc19697e Steve Holden <sholden@holdenweb.com>:
Fred Drake <fdrake@acm.org>
parents: 15619
diff changeset
417 as part of the string, \emph{not} as a line continuation.
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
418
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
419
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
420 \subsection{String literal concatenation\label{string-catenation}}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
421
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
422 Multiple adjacent string literals (delimited by whitespace), possibly
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
423 using different quoting conventions, are allowed, and their meaning is
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
424 the same as their concatenation. Thus, \code{"hello" 'world'} is
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
425 equivalent to \code{"helloworld"}. This feature can be used to reduce
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
426 the number of backslashes needed, to split long strings conveniently
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
427 across long lines, or even to add comments to parts of strings, for
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
428 example:
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
429
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
430 \begin{verbatim}
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
431 re.compile("[A-Za-z_]" # letter or underscore
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
432 "[A-Za-z0-9_]*" # letter, digit or underscore
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
433 )
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
434 \end{verbatim}
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
435
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
436 Note that this feature is defined at the syntactical level, but
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
437 implemented at compile time. The `+' operator must be used to
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
438 concatenate string expressions at run time. Also note that literal
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
439 concatenation can use different quoting styles for each component
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
440 (even mixing raw strings and triple quoted strings).
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
441
15415
0f00b6c7b9b9 Note that readframes() returns data in linear format, even if the original
Fred Drake <fdrake@acm.org>
parents: 14160
diff changeset
442
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
443 \subsection{Numeric literals\label{numbers}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
444
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
445 There are four types of numeric literals: plain integers, long
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
446 integers, floating point numbers, and imaginary numbers. There are no
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
447 complex literals (complex numbers can be formed by adding a real
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
448 number and an imaginary number).
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
449 \index{number}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
450 \index{numeric literal}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
451 \index{integer literal}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
452 \index{plain integer literal}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
453 \index{long integer literal}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
454 \index{floating point literal}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
455 \index{hexadecimal literal}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
456 \index{octal literal}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
457 \index{decimal literal}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
458 \index{imaginary literal}
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
459 \index{complex literal}
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
460
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
461 Note that numeric literals do not include a sign; a phrase like
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
462 \code{-1} is actually an expression composed of the unary operator
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
463 `\code{-}' and the literal \code{1}.
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
464
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
465
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
466 \subsection{Integer and long integer literals\label{integers}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
467
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
468 Integer and long integer literals are described by the following
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
469 lexical definitions:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
470
18429
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
471 \begin{productionlist}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
472 \production{longinteger}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
473 {\token{integer} ("l" | "L")}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
474 \production{integer}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
475 {\token{decimalinteger} | \token{octinteger} | \token{hexinteger}}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
476 \production{decimalinteger}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
477 {\token{nonzerodigit} \token{digit}* | "0"}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
478 \production{octinteger}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
479 {"0" \token{octdigit}+}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
480 \production{hexinteger}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
481 {"0" ("x" | "X") \token{hexdigit}+}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
482 \production{nonzerodigit}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
483 {"1"..."9"}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
484 \production{octdigit}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
485 {"0"..."7"}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
486 \production{hexdigit}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
487 {\token{digit} | "a"..."f" | "A"..."F"}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
488 \end{productionlist}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
489
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
490 Although both lower case `l' and upper case `L' are allowed as suffix
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
491 for long integers, it is strongly recommended to always use `L', since
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
492 the letter `l' looks too much like the digit `1'.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
493
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
494 Plain integer decimal literals must be at most 2147483647 (i.e., the
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
495 largest positive integer, using 32-bit arithmetic). Plain octal and
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
496 hexadecimal literals may be as large as 4294967295, but values larger
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
497 than 2147483647 are converted to a negative value by subtracting
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
498 4294967296. There is no limit for long integer literals apart from
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
499 what can be stored in available memory.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
500
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
501 Some examples of plain and long integer literals:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
502
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
503 \begin{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
504 7 2147483647 0177 0x80000000
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
505 3L 79228162514264337593543950336L 0377L 0x100000000L
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
506 \end{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
507
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
508
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
509 \subsection{Floating point literals\label{floating}}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
510
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
511 Floating point literals are described by the following lexical
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
512 definitions:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
513
18429
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
514 \begin{productionlist}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
515 \production{floatnumber}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
516 {\token{pointfloat} | \token{exponentfloat}}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
517 \production{pointfloat}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
518 {[\token{intpart}] \token{fraction} | \token{intpart} "."}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
519 \production{exponentfloat}
19621
0bec699783d0 SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents: 19257
diff changeset
520 {(\token{intpart} | \token{pointfloat})
18429
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
521 \token{exponent}}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
522 \production{intpart}
19621
0bec699783d0 SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents: 19257
diff changeset
523 {\token{digit}+}
18429
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
524 \production{fraction}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
525 {"." \token{digit}+}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
526 \production{exponent}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
527 {("e" | "E") ["+" | "-"] \token{digit}+}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
528 \end{productionlist}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
529
19621
0bec699783d0 SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents: 19257
diff changeset
530 Note that the integer and exponent parts of floating point numbers
0bec699783d0 SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents: 19257
diff changeset
531 can look like octal integers, but are interpreted using radix 10. For
0bec699783d0 SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents: 19257
diff changeset
532 example, \samp{077e010} is legal, and denotes the same number
0bec699783d0 SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents: 19257
diff changeset
533 as \samp{77e10}.
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
534 The allowed range of floating point literals is
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
535 implementation-dependent.
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
536 Some examples of floating point literals:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
537
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
538 \begin{verbatim}
19621
0bec699783d0 SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents: 19257
diff changeset
539 3.14 10. .001 1e100 3.14e-10 0e0
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
540 \end{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
541
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
542 Note that numeric literals do not include a sign; a phrase like
8337
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
543 \code{-1} is actually an expression composed of the operator
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
544 \code{-} and the literal \code{1}.
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
545
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
546
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
547 \subsection{Imaginary literals\label{imaginary}}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
548
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
549 Imaginary literals are described by the following lexical definitions:
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
550
18429
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
551 \begin{productionlist}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
552 \production{imagnumber}{(\token{floatnumber} | \token{intpart}) ("j" | "J")}
9c354e69a489 Change the grammar productions to use the new productionlist environment;
Fred Drake <fdrake@acm.org>
parents: 18245
diff changeset
553 \end{productionlist}
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
554
12217
5ea773413531 Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10356
diff changeset
555 An imaginary literal yields a complex number with a real part of
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
556 0.0. Complex numbers are represented as a pair of floating point
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
557 numbers and have the same restrictions on their range. To create a
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
558 complex number with a nonzero real part, add a floating point number
8736
6c20ca723180 e.g. -> e.g.,
Guido van Rossum <guido@python.org>
parents: 8508
diff changeset
559 to it, e.g., \code{(3+4j)}. Some examples of imaginary literals:
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
560
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
561 \begin{verbatim}
8736
6c20ca723180 e.g. -> e.g.,
Guido van Rossum <guido@python.org>
parents: 8508
diff changeset
562 3.14j 10.j 10j .001j 1e100j 3.14e-10j
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
563 \end{verbatim}
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
564
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
565
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
566 \section{Operators\label{operators}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
567
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
568 The following tokens are operators:
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
569 \index{operators}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
570
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
571 \begin{verbatim}
19054
11bba30e9c28 "Thin" version of floor division docs: add // to the list of operators
Fred Drake <fdrake@acm.org>
parents: 18772
diff changeset
572 + - * ** / // %
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
573 << >> & | ^ ~
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
574 < > <= >= == != <>
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
575 \end{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
576
8337
8d90e781ada8 Updated markup style (got rid of \verb@...@, mostly).
Fred Drake <fdrake@acm.org>
parents: 8231
diff changeset
577 The comparison operators \code{<>} and \code{!=} are alternate
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
578 spellings of the same operator. \code{!=} is the preferred spelling;
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
579 \code{<>} is obsolescent.
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
580
18236
f8287d84b755 Add "yeild" to the list of keywords.
Fred Drake <fdrake@acm.org>
parents: 16591
diff changeset
581
8777
00524555ef17 Make sure all chapters, sections, and subsections have a \label to give them
Fred Drake <fdrake@acm.org>
parents: 8752
diff changeset
582 \section{Delimiters\label{delimiters}}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
583
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
584 The following tokens serve as delimiters in the grammar:
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
585 \index{delimiters}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
586
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
587 \begin{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
588 ( ) [ ] { }
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
589 , : . ` = ;
19054
11bba30e9c28 "Thin" version of floor division docs: add // to the list of operators
Fred Drake <fdrake@acm.org>
parents: 18772
diff changeset
590 += -= *= /= //= %=
11bba30e9c28 "Thin" version of floor division docs: add // to the list of operators
Fred Drake <fdrake@acm.org>
parents: 18772
diff changeset
591 &= |= ^= >>= <<= **=
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
592 \end{verbatim}
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
593
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
594 The period can also occur in floating-point and imaginary literals. A
12217
5ea773413531 Merged changes from the 1.5.2p2 release.
Fred Drake <fdrake@acm.org>
parents: 10356
diff changeset
595 sequence of three periods has a special meaning as an ellipsis in slices.
14160
5468b6e3b96a Rough and incomplete documentation on augmented assignment, which follows
Thomas Wouters <thomas@python.org>
parents: 12217
diff changeset
596 The second half of the list, the augmented assignment operators, serve
5468b6e3b96a Rough and incomplete documentation on augmented assignment, which follows
Thomas Wouters <thomas@python.org>
parents: 12217
diff changeset
597 lexically as delimiters, but also perform an operation.
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
598
21062
bc02c3b09626 Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents: 19621
diff changeset
599 The following printing \ASCII{} characters have special meaning as part
8508
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
600 of other tokens or are otherwise significant to the lexical analyzer:
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
601
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
602 \begin{verbatim}
ded69d12cc68 Lots of changes to get this in sync with the Frame version.
Guido van Rossum <guido@python.org>
parents: 8337
diff changeset
603 ' " # \
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
604 \end{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
605
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
606 The following printing \ASCII{} characters are not used in Python. Their
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
607 occurrence outside string literals and comments is an unconditional
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
608 error:
21062
bc02c3b09626 Clean up some markup cruft. A number of the macros that take no
Fred Drake <fdrake@acm.org>
parents: 19621
diff changeset
609 \index{ASCII@\ASCII}
8231
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
610
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
611 \begin{verbatim}
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
612 @ $ ?
a103cf6d3845 The Python Reference Manual.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
613 \end{verbatim}