Mercurial > cpython-lru_cache-weakref
annotate Doc/ref2.tex @ 3720:b341def4eef8 legacy-trunk
Ignore latex intermediate products.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 26 Jun 1996 19:30:01 +0000 |
| parents | 68d7eae6cbd6 |
| children | d6897385c318 |
| rev | line source |
|---|---|
| 949 | 1 \chapter{Lexical analysis} |
| 2 | |
| 3 A Python program is read by a {\em parser}. Input to the parser is a | |
| 4 stream of {\em tokens}, generated by the {\em lexical analyzer}. This | |
| 5 chapter describes how the lexical analyzer breaks a file into tokens. | |
| 6 \index{lexical analysis} | |
| 7 \index{parser} | |
| 8 \index{token} | |
| 9 | |
| 10 \section{Line structure} | |
| 11 | |
| 12 A Python program is divided in a number of logical lines. The end of | |
| 13 a logical line is represented by the token NEWLINE. Statements cannot | |
| 14 cross logical line boundaries except where NEWLINE is allowed by the | |
| 15 syntax (e.g. between statements in compound statements). | |
| 16 \index{line structure} | |
| 17 \index{logical line} | |
| 18 \index{NEWLINE token} | |
| 19 | |
| 20 \subsection{Comments} | |
| 21 | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
22 A comment starts with a hash character (\verb@#@) that is not part of |
| 949 | 23 a string literal, and ends at the end of the physical line. A comment |
| 24 always signifies the end of the logical line. Comments are ignored by | |
| 25 the syntax. | |
| 26 \index{comment} | |
| 27 \index{logical line} | |
| 28 \index{physical line} | |
| 29 \index{hash character} | |
| 30 | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
31 \subsection{Explicit line joining} |
| 949 | 32 |
| 33 Two or more physical lines may be joined into logical lines using | |
| 34 backslash characters (\verb/\/), as follows: when a physical line ends | |
| 35 in a backslash that is not part of a string literal or comment, it is | |
| 36 joined with the following forming a single logical line, deleting the | |
| 37 backslash and the following end-of-line character. For example: | |
| 38 \index{physical line} | |
| 39 \index{line joining} | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
40 \index{line continuation} |
| 949 | 41 \index{backslash character} |
| 42 % | |
| 43 \begin{verbatim} | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
44 if 1900 < year < 2100 and 1 <= month <= 12 \ |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
45 and 1 <= day <= 31 and 0 <= hour < 24 \ |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
46 and 0 <= minute < 60 and 0 <= second < 60: # Looks like a valid date |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
47 return 1 |
| 949 | 48 \end{verbatim} |
| 49 | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
50 A line ending in a backslash cannot carry a comment; a backslash does |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
51 not continue a comment (but it does continue a string literal, see |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
52 below). |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
53 |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
54 \subsection{Implicit line joining} |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
55 |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
56 Expressions in parentheses, square brackets or curly braces can be |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
57 split over more than one physical line without using backslashes. |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
58 For example: |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
59 |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
60 \begin{verbatim} |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
61 month_names = ['Januari', 'Februari', 'Maart', # These are the |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
62 'April', 'Mei', 'Juni', # Dutch names |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
63 'Juli', 'Augustus', 'September', # for the months |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
64 'Oktober', 'November', 'December'] # of the year |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
65 \end{verbatim} |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
66 |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
67 Implicitly continued lines can carry comments. The indentation of the |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
68 continuation lines is not important. Blank continuation lines are |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
69 allowed. |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
70 |
| 949 | 71 \subsection{Blank lines} |
| 72 | |
| 73 A logical line that contains only spaces, tabs, and possibly a | |
| 74 comment, is ignored (i.e., no NEWLINE token is generated), except that | |
| 75 during interactive input of statements, an entirely blank logical line | |
| 76 terminates a multi-line statement. | |
| 77 \index{blank line} | |
| 78 | |
| 79 \subsection{Indentation} | |
| 80 | |
| 81 Leading whitespace (spaces and tabs) at the beginning of a logical | |
| 82 line is used to compute the indentation level of the line, which in | |
| 83 turn is used to determine the grouping of statements. | |
| 84 \index{indentation} | |
| 85 \index{whitespace} | |
| 86 \index{leading whitespace} | |
| 87 \index{space} | |
| 88 \index{tab} | |
| 89 \index{grouping} | |
| 90 \index{statement grouping} | |
| 91 | |
| 92 First, tabs are replaced (from left to right) by one to eight spaces | |
| 93 such that the total number of characters up to there is a multiple of | |
| 94 eight (this is intended to be the same rule as used by {\UNIX}). The | |
| 95 total number of spaces preceding the first non-blank character then | |
| 96 determines the line's indentation. Indentation cannot be split over | |
| 97 multiple physical lines using backslashes. | |
| 98 | |
| 99 The indentation levels of consecutive lines are used to generate | |
| 100 INDENT and DEDENT tokens, using a stack, as follows. | |
| 101 \index{INDENT token} | |
| 102 \index{DEDENT token} | |
| 103 | |
| 104 Before the first line of the file is read, a single zero is pushed on | |
| 105 the stack; this will never be popped off again. The numbers pushed on | |
| 106 the stack will always be strictly increasing from bottom to top. At | |
| 107 the beginning of each logical line, the line's indentation level is | |
| 108 compared to the top of the stack. If it is equal, nothing happens. | |
| 109 If it is larger, it is pushed on the stack, and one INDENT token is | |
| 110 generated. If it is smaller, it {\em must} be one of the numbers | |
| 111 occurring on the stack; all numbers on the stack that are larger are | |
| 112 popped off, and for each number popped off a DEDENT token is | |
| 113 generated. At the end of the file, a DEDENT token is generated for | |
| 114 each number remaining on the stack that is larger than zero. | |
| 115 | |
| 116 Here is an example of a correctly (though confusingly) indented piece | |
| 117 of Python code: | |
| 118 | |
| 119 \begin{verbatim} | |
| 120 def perm(l): | |
| 121 # Compute the list of all permutations of l | |
| 122 | |
| 123 if len(l) <= 1: | |
| 124 return [l] | |
| 125 r = [] | |
| 126 for i in range(len(l)): | |
| 127 s = l[:i] + l[i+1:] | |
| 128 p = perm(s) | |
| 129 for x in p: | |
| 130 r.append(l[i:i+1] + x) | |
| 131 return r | |
| 132 \end{verbatim} | |
| 133 | |
| 134 The following example shows various indentation errors: | |
| 135 | |
| 136 \begin{verbatim} | |
| 137 def perm(l): # error: first line indented | |
| 138 for i in range(len(l)): # error: not indented | |
| 139 s = l[:i] + l[i+1:] | |
| 140 p = perm(l[:i] + l[i+1:]) # error: unexpected indent | |
| 141 for x in p: | |
| 142 r.append(l[i:i+1] + x) | |
| 143 return r # error: inconsistent dedent | |
| 144 \end{verbatim} | |
| 145 | |
| 146 (Actually, the first three errors are detected by the parser; only the | |
| 147 last error is found by the lexical analyzer --- the indentation of | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
148 \verb@return r@ does not match a level popped off the stack.) |
| 949 | 149 |
| 150 \section{Other tokens} | |
| 151 | |
| 152 Besides NEWLINE, INDENT and DEDENT, the following categories of tokens | |
| 153 exist: identifiers, keywords, literals, operators, and delimiters. | |
| 154 Spaces and tabs are not tokens, but serve to delimit tokens. Where | |
| 155 ambiguity exists, a token comprises the longest possible string that | |
| 156 forms a legal token, when read from left to right. | |
| 157 | |
| 158 \section{Identifiers} | |
| 159 | |
| 160 Identifiers (also referred to as names) are described by the following | |
| 161 lexical definitions: | |
| 162 \index{identifier} | |
| 163 \index{name} | |
| 164 | |
| 165 \begin{verbatim} | |
| 166 identifier: (letter|"_") (letter|digit|"_")* | |
| 167 letter: lowercase | uppercase | |
| 168 lowercase: "a"..."z" | |
| 169 uppercase: "A"..."Z" | |
| 170 digit: "0"..."9" | |
| 171 \end{verbatim} | |
| 172 | |
| 173 Identifiers are unlimited in length. Case is significant. | |
| 174 | |
| 175 \subsection{Keywords} | |
| 176 | |
| 177 The following identifiers are used as reserved words, or {\em | |
| 178 keywords} of the language, and cannot be used as ordinary | |
| 179 identifiers. They must be spelled exactly as written here: | |
| 180 \index{keyword} | |
| 181 \index{reserved word} | |
| 182 | |
| 183 \begin{verbatim} | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
184 access del from lambda return |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
185 and elif global not try |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
186 break else if or while |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
187 class except import pass |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
188 continue finally in print |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
189 def for is raise |
| 949 | 190 \end{verbatim} |
| 191 | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
192 % When adding keywords, pipe it through keywords.py for reformatting |
| 949 | 193 |
| 194 \section{Literals} \label{literals} | |
| 195 | |
| 196 Literals are notations for constant values of some built-in types. | |
| 197 \index{literal} | |
| 198 \index{constant} | |
| 199 | |
| 200 \subsection{String literals} | |
| 201 | |
| 202 String literals are described by the following lexical definitions: | |
| 203 \index{string literal} | |
| 204 | |
| 205 \begin{verbatim} | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
206 stringliteral: shortstring | longstring |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
207 shortstring: "'" shortstringitem* "'" | '"' shortstringitem* '"' |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
208 longstring: "'''" longstringitem* "'''" | '"""' longstringitem* '"""' |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
209 shortstringitem: shortstringchar | escapeseq |
|
2820
68d7eae6cbd6
add missing definitin of longstringitem
Guido van Rossum <guido@python.org>
parents:
2562
diff
changeset
|
210 longstringitem: longstringchar | escapeseq |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
211 shortstringchar: <any ASCII character except "\" or newline or the quote> |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
212 longstringchar: <any ASCII character except "\"> |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
213 escapeseq: "\" <any ASCII character> |
| 949 | 214 \end{verbatim} |
| 215 \index{ASCII} | |
| 216 | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
217 In ``long strings'' (strings surrounded by sets of three quotes), |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
218 unescaped newlines and quotes are allowed (and are retained), except |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
219 that three unescaped quotes in a row terminate the string. (A |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
220 ``quote'' is the character used to open the string, i.e. either |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
221 \verb/'/ or \verb/"/.) |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
222 |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
223 Escape sequences in strings are interpreted according to rules similar |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
224 to those used by Standard C. The recognized escape sequences are: |
| 949 | 225 \index{physical line} |
| 226 \index{escape sequence} | |
| 227 \index{Standard C} | |
| 228 \index{C} | |
| 229 | |
| 230 \begin{center} | |
| 231 \begin{tabular}{|l|l|} | |
| 232 \hline | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
233 \verb/\/{\em newline} & Ignored \\ |
| 949 | 234 \verb/\\/ & Backslash (\verb/\/) \\ |
| 235 \verb/\'/ & Single quote (\verb/'/) \\ | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
236 \verb/\"/ & Double quote (\verb/"/) \\ |
|
2550
0f6ff45bd816
replace ASCII by macro call
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
237 \verb/\a/ & \ASCII{} Bell (BEL) \\ |
|
0f6ff45bd816
replace ASCII by macro call
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
238 \verb/\b/ & \ASCII{} Backspace (BS) \\ |
|
0f6ff45bd816
replace ASCII by macro call
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
239 %\verb/\E/ & \ASCII{} Escape (ESC) \\ |
|
0f6ff45bd816
replace ASCII by macro call
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
240 \verb/\f/ & \ASCII{} Formfeed (FF) \\ |
|
0f6ff45bd816
replace ASCII by macro call
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
241 \verb/\n/ & \ASCII{} Linefeed (LF) \\ |
|
0f6ff45bd816
replace ASCII by macro call
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
242 \verb/\r/ & \ASCII{} Carriage Return (CR) \\ |
|
0f6ff45bd816
replace ASCII by macro call
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
243 \verb/\t/ & \ASCII{} Horizontal Tab (TAB) \\ |
|
0f6ff45bd816
replace ASCII by macro call
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
244 \verb/\v/ & \ASCII{} Vertical Tab (VT) \\ |
|
0f6ff45bd816
replace ASCII by macro call
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
245 \verb/\/{\em ooo} & \ASCII{} character with octal value {\em ooo} \\ |
|
0f6ff45bd816
replace ASCII by macro call
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
246 \verb/\x/{\em xx...} & \ASCII{} character with hex value {\em xx...} \\ |
| 949 | 247 \hline |
| 248 \end{tabular} | |
| 249 \end{center} | |
| 250 \index{ASCII} | |
| 251 | |
| 252 In strict compatibility with Standard C, up to three octal digits are | |
| 253 accepted, but an unlimited number of hex digits is taken to be part of | |
| 254 the hex escape (and then the lower 8 bits of the resulting hex number | |
| 255 are used in all current implementations...). | |
| 256 | |
| 257 All unrecognized escape sequences are left in the string unchanged, | |
| 258 i.e., {\em the backslash is left in the string.} (This behavior is | |
| 259 useful when debugging: if an escape sequence is mistyped, the | |
| 260 resulting output is more easily recognized as broken. It also helps a | |
| 261 great deal for string literals used as regular expressions or | |
| 262 otherwise passed to other modules that do their own escape handling.) | |
| 263 \index{unrecognized escape sequence} | |
| 264 | |
| 265 \subsection{Numeric literals} | |
| 266 | |
| 267 There are three types of numeric literals: plain integers, long | |
| 268 integers, and floating point numbers. | |
| 269 \index{number} | |
| 270 \index{numeric literal} | |
| 271 \index{integer literal} | |
| 272 \index{plain integer literal} | |
| 273 \index{long integer literal} | |
| 274 \index{floating point literal} | |
| 275 \index{hexadecimal literal} | |
| 276 \index{octal literal} | |
| 277 \index{decimal literal} | |
| 278 | |
| 279 Integer and long integer literals are described by the following | |
| 280 lexical definitions: | |
| 281 | |
| 282 \begin{verbatim} | |
| 283 longinteger: integer ("l"|"L") | |
| 284 integer: decimalinteger | octinteger | hexinteger | |
| 285 decimalinteger: nonzerodigit digit* | "0" | |
| 286 octinteger: "0" octdigit+ | |
| 287 hexinteger: "0" ("x"|"X") hexdigit+ | |
| 288 | |
| 289 nonzerodigit: "1"..."9" | |
| 290 octdigit: "0"..."7" | |
| 291 hexdigit: digit|"a"..."f"|"A"..."F" | |
| 292 \end{verbatim} | |
| 293 | |
| 294 Although both lower case `l' and upper case `L' are allowed as suffix | |
| 295 for long integers, it is strongly recommended to always use `L', since | |
| 296 the letter `l' looks too much like the digit `1'. | |
| 297 | |
|
2562
3828206c2dc0
made palatable for latex2html:
Guido van Rossum <guido@python.org>
parents:
2550
diff
changeset
|
298 Plain integer decimal literals must be at most 2147483647 (i.e., the |
|
3828206c2dc0
made palatable for latex2html:
Guido van Rossum <guido@python.org>
parents:
2550
diff
changeset
|
299 largest positive integer, using 32-bit arithmetic). Plain octal and |
|
3828206c2dc0
made palatable for latex2html:
Guido van Rossum <guido@python.org>
parents:
2550
diff
changeset
|
300 hexadecimal literals may be as large as 4294967295, but values larger |
|
3828206c2dc0
made palatable for latex2html:
Guido van Rossum <guido@python.org>
parents:
2550
diff
changeset
|
301 than 2147483647 are converted to a negative value by subtracting |
|
3828206c2dc0
made palatable for latex2html:
Guido van Rossum <guido@python.org>
parents:
2550
diff
changeset
|
302 4294967296. There is no limit for long integer literals apart from |
|
3828206c2dc0
made palatable for latex2html:
Guido van Rossum <guido@python.org>
parents:
2550
diff
changeset
|
303 what can be stored in available memory. |
| 949 | 304 |
| 305 Some examples of plain and long integer literals: | |
| 306 | |
| 307 \begin{verbatim} | |
| 308 7 2147483647 0177 0x80000000 | |
| 309 3L 79228162514264337593543950336L 0377L 0x100000000L | |
| 310 \end{verbatim} | |
| 311 | |
| 312 Floating point literals are described by the following lexical | |
| 313 definitions: | |
| 314 | |
| 315 \begin{verbatim} | |
| 316 floatnumber: pointfloat | exponentfloat | |
| 317 pointfloat: [intpart] fraction | intpart "." | |
| 318 exponentfloat: (intpart | pointfloat) exponent | |
| 319 intpart: digit+ | |
| 320 fraction: "." digit+ | |
| 321 exponent: ("e"|"E") ["+"|"-"] digit+ | |
| 322 \end{verbatim} | |
| 323 | |
| 324 The allowed range of floating point literals is | |
| 325 implementation-dependent. | |
| 326 | |
| 327 Some examples of floating point literals: | |
| 328 | |
| 329 \begin{verbatim} | |
| 330 3.14 10. .001 1e100 3.14e-10 | |
| 331 \end{verbatim} | |
| 332 | |
| 333 Note that numeric literals do not include a sign; a phrase like | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
334 \verb@-1@ is actually an expression composed of the operator |
|
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
335 \verb@-@ and the literal \verb@1@. |
| 949 | 336 |
| 337 \section{Operators} | |
| 338 | |
| 339 The following tokens are operators: | |
| 340 \index{operators} | |
| 341 | |
| 342 \begin{verbatim} | |
| 343 + - * / % | |
| 344 << >> & | ^ ~ | |
| 345 < == > <= <> != >= | |
| 346 \end{verbatim} | |
| 347 | |
|
1751
ec25aad43724
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
949
diff
changeset
|
348 The comparison operators \verb@<>@ and \verb@!=@ are alternate |
| 949 | 349 spellings of the same operator. |
| 350 | |
| 351 \section{Delimiters} | |
| 352 | |
| 353 The following tokens serve as delimiters or otherwise have a special | |
| 354 meaning: | |
| 355 \index{delimiters} | |
| 356 | |
| 357 \begin{verbatim} | |
| 358 ( ) [ ] { } | |
|
1767
907605320a5f
Lots of small corrections by Andrew Kuchling (plus all new rotor docs)
Guido van Rossum <guido@python.org>
parents:
1751
diff
changeset
|
359 , : . " ` ' |
|
907605320a5f
Lots of small corrections by Andrew Kuchling (plus all new rotor docs)
Guido van Rossum <guido@python.org>
parents:
1751
diff
changeset
|
360 = ; |
| 949 | 361 \end{verbatim} |
| 362 | |
|
2550
0f6ff45bd816
replace ASCII by macro call
Guido van Rossum <guido@python.org>
parents:
1767
diff
changeset
|
363 The following printing \ASCII{} characters are not used in Python. Their |
| 949 | 364 occurrence outside string literals and comments is an unconditional |
| 365 error: | |
| 366 \index{ASCII} | |
| 367 | |
| 368 \begin{verbatim} | |
|
1767
907605320a5f
Lots of small corrections by Andrew Kuchling (plus all new rotor docs)
Guido van Rossum <guido@python.org>
parents:
1751
diff
changeset
|
369 @ $ ? |
| 949 | 370 \end{verbatim} |
| 371 | |
| 372 They may be used by future versions of the language though! |
