blob: 2eef6eeba3cfbdc5cb02921da9ea999249ae7a91 [file] [log] [blame]
Fred Drakef6669171998-05-06 19:52:49 +00001\chapter{Lexical analysis}
2
Fred Drake5c07d9b1998-05-14 19:37:06 +00003A Python program is read by a \emph{parser}. Input to the parser is a
4stream of \emph{tokens}, generated by the \emph{lexical analyzer}. This
Fred Drakef6669171998-05-06 19:52:49 +00005chapter describes how the lexical analyzer breaks a file into tokens.
6\index{lexical analysis}
7\index{parser}
8\index{token}
9
Guido van Rossum60f2f0c1998-06-15 18:00:50 +000010Python uses the 7-bit \ASCII{} character set for program text and string
11literals. 8-bit characters may be used in string literals and comments
12but their interpretation is platform dependent; the proper way to
13insert 8-bit characters in string literals is by using octal or
14hexadecimal escape sequences.
15
16The run-time character set depends on the I/O devices connected to the
17program but is generally a superset of \ASCII{}.
18
19\strong{Future compatibility note:} It may be tempting to assume that the
20character set for 8-bit characters is ISO Latin-1 (an \ASCII{}
21superset that covers most western languages that use the Latin
22alphabet), but it is possible that in the future Unicode text editors
23will become common. These generally use the UTF-8 encoding, which is
24also an \ASCII{} superset, but with very different use for the
25characters with ordinals 128-255. While there is no consensus on this
26subject yet, it is unwise to assume either Latin-1 or UTF-8, even
27though the current implementation appears to favor Latin-1. This
28applies both to the source character set and the run-time character
29set.
30
Fred Drakef6669171998-05-06 19:52:49 +000031\section{Line structure}
32
Guido van Rossum60f2f0c1998-06-15 18:00:50 +000033A Python program is divided into a number of \emph{logical lines}.
34\index{line structure}
35
36\subsection{Logical Lines}
37
38The end of
Fred Drakef6669171998-05-06 19:52:49 +000039a logical line is represented by the token NEWLINE. Statements cannot
40cross logical line boundaries except where NEWLINE is allowed by the
41syntax (e.g. between statements in compound statements).
Guido van Rossum60f2f0c1998-06-15 18:00:50 +000042A logical line is constructed from one or more \emph{physical lines}
43by following the explicit or implicit \emph{line joining} rules.
Fred Drakef6669171998-05-06 19:52:49 +000044\index{logical line}
Guido van Rossum60f2f0c1998-06-15 18:00:50 +000045\index{physical line}
46\index{line joining}
Fred Drakef6669171998-05-06 19:52:49 +000047\index{NEWLINE token}
48
Guido van Rossum60f2f0c1998-06-15 18:00:50 +000049\subsection{Physical lines}
50
51A physical line ends in whatever the current platform's convention is
52for terminating lines. On \UNIX{}, this is the \ASCII{} LF (linefeed)
53character. On DOS/Windows, it is the \ASCII{} sequence CR LF (return
54followed by linefeed). On Macintosh, it is the \ASCII{} CR (return)
55character.
56
Fred Drakef6669171998-05-06 19:52:49 +000057\subsection{Comments}
58
Fred Drake5c07d9b1998-05-14 19:37:06 +000059A comment starts with a hash character (\code{\#}) that is not part of
Fred Drakef6669171998-05-06 19:52:49 +000060a string literal, and ends at the end of the physical line. A comment
Guido van Rossum60f2f0c1998-06-15 18:00:50 +000061signifies the end of the logical line unless the implicit line joining
62rules are invoked.
63Comments are ignored by the syntax; they are not tokens.
Fred Drakef6669171998-05-06 19:52:49 +000064\index{comment}
Fred Drakef6669171998-05-06 19:52:49 +000065\index{hash character}
66
67\subsection{Explicit line joining}
68
69Two or more physical lines may be joined into logical lines using
Fred Drake5c07d9b1998-05-14 19:37:06 +000070backslash characters (\code{\e}), as follows: when a physical line ends
Fred Drakef6669171998-05-06 19:52:49 +000071in a backslash that is not part of a string literal or comment, it is
72joined with the following forming a single logical line, deleting the
73backslash and the following end-of-line character. For example:
74\index{physical line}
75\index{line joining}
76\index{line continuation}
77\index{backslash character}
78%
79\begin{verbatim}
80if 1900 < year < 2100 and 1 <= month <= 12 \
81 and 1 <= day <= 31 and 0 <= hour < 24 \
82 and 0 <= minute < 60 and 0 <= second < 60: # Looks like a valid date
83 return 1
84\end{verbatim}
85
Guido van Rossum60f2f0c1998-06-15 18:00:50 +000086A line ending in a backslash cannot carry a comment. A backslash does
87not continue a comment. A backslash does not continue a token except
88for string literals (i.e., tokens other than string literals cannot be
89split across physical lines using a backslash). A backslash is
90illegal elsewhere on a line outside a string literal.
Fred Drakef6669171998-05-06 19:52:49 +000091
92\subsection{Implicit line joining}
93
94Expressions in parentheses, square brackets or curly braces can be
95split over more than one physical line without using backslashes.
96For example:
97
98\begin{verbatim}
99month_names = ['Januari', 'Februari', 'Maart', # These are the
100 'April', 'Mei', 'Juni', # Dutch names
101 'Juli', 'Augustus', 'September', # for the months
102 'Oktober', 'November', 'December'] # of the year
103\end{verbatim}
104
105Implicitly continued lines can carry comments. The indentation of the
106continuation lines is not important. Blank continuation lines are
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000107allowed. There is no NEWLINE token between implicit continuation
108lines. Implicitly continued lines can also occur within triple-quoted
109strings (see below); in that case they cannot carry comments.
Fred Drakef6669171998-05-06 19:52:49 +0000110
111\subsection{Blank lines}
112
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000113A logical line that contains only spaces, tabs, formfeeds and possibly a
Fred Drakef6669171998-05-06 19:52:49 +0000114comment, is ignored (i.e., no NEWLINE token is generated), except that
115during interactive input of statements, an entirely blank logical line
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000116(i.e. one containing not even whitespace or a comment)
Fred Drakef6669171998-05-06 19:52:49 +0000117terminates a multi-line statement.
118\index{blank line}
119
120\subsection{Indentation}
121
122Leading whitespace (spaces and tabs) at the beginning of a logical
123line is used to compute the indentation level of the line, which in
124turn is used to determine the grouping of statements.
125\index{indentation}
126\index{whitespace}
127\index{leading whitespace}
128\index{space}
129\index{tab}
130\index{grouping}
131\index{statement grouping}
132
133First, tabs are replaced (from left to right) by one to eight spaces
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000134such that the total number of characters up to and including the
135replacement is a multiple of
Fred Drake5c07d9b1998-05-14 19:37:06 +0000136eight (this is intended to be the same rule as used by \UNIX{}). The
Fred Drakef6669171998-05-06 19:52:49 +0000137total number of spaces preceding the first non-blank character then
138determines the line's indentation. Indentation cannot be split over
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000139multiple physical lines using backslashes; the whitespace up to the
140first backslash determines the indentation.
141
142\strong{Cross-platform compatibility note:} because of the nature of
143text editors on non-UNIX platforms, it is unwise to use a mixture of
144spaces and tabs for the indentation in a single source file.
145
146A formfeed character may be present at the start of the line; it will
147be ignored for the indentation calculations above. A formfeed
148characters occurring elsewhere in the leading whitespace have an
149undefined effect (for instance, they may reset the space count to
150zero).
Fred Drakef6669171998-05-06 19:52:49 +0000151
152The indentation levels of consecutive lines are used to generate
153INDENT and DEDENT tokens, using a stack, as follows.
154\index{INDENT token}
155\index{DEDENT token}
156
157Before the first line of the file is read, a single zero is pushed on
158the stack; this will never be popped off again. The numbers pushed on
159the stack will always be strictly increasing from bottom to top. At
160the beginning of each logical line, the line's indentation level is
161compared to the top of the stack. If it is equal, nothing happens.
162If it is larger, it is pushed on the stack, and one INDENT token is
Fred Drake5c07d9b1998-05-14 19:37:06 +0000163generated. If it is smaller, it \emph{must} be one of the numbers
Fred Drakef6669171998-05-06 19:52:49 +0000164occurring on the stack; all numbers on the stack that are larger are
165popped off, and for each number popped off a DEDENT token is
166generated. At the end of the file, a DEDENT token is generated for
167each number remaining on the stack that is larger than zero.
168
169Here is an example of a correctly (though confusingly) indented piece
170of Python code:
171
172\begin{verbatim}
173def perm(l):
174 # Compute the list of all permutations of l
Fred Drakef6669171998-05-06 19:52:49 +0000175 if len(l) <= 1:
176 return [l]
177 r = []
178 for i in range(len(l)):
179 s = l[:i] + l[i+1:]
180 p = perm(s)
181 for x in p:
182 r.append(l[i:i+1] + x)
183 return r
184\end{verbatim}
185
186The following example shows various indentation errors:
187
188\begin{verbatim}
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000189 def perm(l): # error: first line indented
Fred Drakef6669171998-05-06 19:52:49 +0000190 for i in range(len(l)): # error: not indented
191 s = l[:i] + l[i+1:]
192 p = perm(l[:i] + l[i+1:]) # error: unexpected indent
193 for x in p:
194 r.append(l[i:i+1] + x)
195 return r # error: inconsistent dedent
196\end{verbatim}
197
198(Actually, the first three errors are detected by the parser; only the
199last error is found by the lexical analyzer --- the indentation of
Fred Drake5c07d9b1998-05-14 19:37:06 +0000200\code{return r} does not match a level popped off the stack.)
Fred Drakef6669171998-05-06 19:52:49 +0000201
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000202\subsection{Whitespace between tokens}
203
204Except at the beginning of a logical line or in string literals, the
205whitespace characters space, tab and formfeed can be used
206interchangeably to separate tokens. Whitespace is needed between two
207tokens only if their concatenation could otherwise be interpreted as a
208different token (e.g., ab is one token, but a b is two tokens).
209
Fred Drakef6669171998-05-06 19:52:49 +0000210\section{Other tokens}
211
212Besides NEWLINE, INDENT and DEDENT, the following categories of tokens
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000213exist: \emph{identifiers}, \emph{keywords}, \emph{literals},
214\emph{operators}, and \emph{delimiters}.
215Whitespace characters (other than line terminators, discussed earlier)
216are not tokens, but serve to delimit tokens.
217Where
Fred Drakef6669171998-05-06 19:52:49 +0000218ambiguity exists, a token comprises the longest possible string that
219forms a legal token, when read from left to right.
220
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000221\section{Identifiers and keywords}
Fred Drakef6669171998-05-06 19:52:49 +0000222
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000223Identifiers (also referred to as \emph{names}) are described by the following
Fred Drakef6669171998-05-06 19:52:49 +0000224lexical definitions:
225\index{identifier}
226\index{name}
227
228\begin{verbatim}
229identifier: (letter|"_") (letter|digit|"_")*
230letter: lowercase | uppercase
231lowercase: "a"..."z"
232uppercase: "A"..."Z"
233digit: "0"..."9"
234\end{verbatim}
235
236Identifiers are unlimited in length. Case is significant.
237
238\subsection{Keywords}
239
Fred Drake5c07d9b1998-05-14 19:37:06 +0000240The following identifiers are used as reserved words, or
241\emph{keywords} of the language, and cannot be used as ordinary
242identifiers. They must be spelled exactly as written here:%
243\index{keyword}%
Fred Drakef6669171998-05-06 19:52:49 +0000244\index{reserved word}
245
246\begin{verbatim}
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000247and del for is raise
248assert elif from lambda return
249break else global not try
250class except if or while
251continue exec import pass
252def finally in print
Fred Drakef6669171998-05-06 19:52:49 +0000253\end{verbatim}
254
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000255% When adding keywords, use reswords.py for reformatting
256
257\subsection{Reserved classes of identifiers}
258
259Certain classes of identifiers (besides keywords) have special
260meanings. These are:
261
262\begin{center}
263\begin{tabular}{|l|l|}
264\hline
265Form & Meaning \\
266\hline
267\code{_*} & Not imported by \code{from \var{module} import *} \\
268\code{__*__} & System-defined name \\
269\code{__*} & Class-private name mangling \\
270\hline
271\end{tabular}
272\end{center}
273
274(XXX need section references here.)
Fred Drakef6669171998-05-06 19:52:49 +0000275
276\section{Literals} \label{literals}
277
278Literals are notations for constant values of some built-in types.
279\index{literal}
280\index{constant}
281
282\subsection{String literals}
283
284String literals are described by the following lexical definitions:
285\index{string literal}
286
287\begin{verbatim}
288stringliteral: shortstring | longstring
289shortstring: "'" shortstringitem* "'" | '"' shortstringitem* '"'
290longstring: "'''" longstringitem* "'''" | '"""' longstringitem* '"""'
291shortstringitem: shortstringchar | escapeseq
292longstringitem: longstringchar | escapeseq
293shortstringchar: <any ASCII character except "\" or newline or the quote>
294longstringchar: <any ASCII character except "\">
295escapeseq: "\" <any ASCII character>
296\end{verbatim}
Fred Drake5c07d9b1998-05-14 19:37:06 +0000297\index{ASCII@\ASCII{}}
Fred Drakef6669171998-05-06 19:52:49 +0000298
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000299In plain English: String literals can be enclosed in matching single
300quotes (\code{'}) or double quotes (\code{"}). They can also be
301enclosed in matching groups of three single or double quotes (these
302are generally referred to as \emph{triple-quoted strings}). The
303backslash (\code{\e}) character is used to escape characters that
304otherwise have a special meaning, such as newline, backslash itself,
305or the quote character. String literals may optionally be prefixed
306with a letter `r' or `R'; such strings are called raw strings and use
307different rules for backslash escape sequences.
308\index{triple-quoted string}
309\index{raw string}
310
311In triple-quoted strings,
Fred Drakef6669171998-05-06 19:52:49 +0000312unescaped newlines and quotes are allowed (and are retained), except
313that three unescaped quotes in a row terminate the string. (A
314``quote'' is the character used to open the string, i.e. either
Fred Drake5c07d9b1998-05-14 19:37:06 +0000315\code{'} or \code{"}.)
Fred Drakef6669171998-05-06 19:52:49 +0000316
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000317Unless an `r' or `R' prefix is present, escape sequences in strings
318are interpreted according to rules similar
319to those used by Standard \C{}. The recognized escape sequences are:
Fred Drakef6669171998-05-06 19:52:49 +0000320\index{physical line}
321\index{escape sequence}
322\index{Standard C}
323\index{C}
324
325\begin{center}
326\begin{tabular}{|l|l|}
327\hline
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000328Escape Sequence & Meaning \\
329\hline
Fred Drake5c07d9b1998-05-14 19:37:06 +0000330\code{\e}\emph{newline} & Ignored \\
331\code{\e\e} & Backslash (\code{\e}) \\
332\code{\e'} & Single quote (\code{'}) \\
333\code{\e"} & Double quote (\code{"}) \\
334\code{\e a} & \ASCII{} Bell (BEL) \\
335\code{\e b} & \ASCII{} Backspace (BS) \\
Fred Drake5c07d9b1998-05-14 19:37:06 +0000336\code{\e f} & \ASCII{} Formfeed (FF) \\
337\code{\e n} & \ASCII{} Linefeed (LF) \\
338\code{\e r} & \ASCII{} Carriage Return (CR) \\
339\code{\e t} & \ASCII{} Horizontal Tab (TAB) \\
340\code{\e v} & \ASCII{} Vertical Tab (VT) \\
341\code{\e}\emph{ooo} & \ASCII{} character with octal value \emph{ooo} \\
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000342\code{\e x}\emph{hh...} & \ASCII{} character with hex value \emph{hh...} \\
Fred Drakef6669171998-05-06 19:52:49 +0000343\hline
344\end{tabular}
345\end{center}
Fred Drake5c07d9b1998-05-14 19:37:06 +0000346\index{ASCII@\ASCII{}}
Fred Drakef6669171998-05-06 19:52:49 +0000347
Fred Drake5c07d9b1998-05-14 19:37:06 +0000348In strict compatibility with Standard \C, up to three octal digits are
Fred Drakef6669171998-05-06 19:52:49 +0000349accepted, but an unlimited number of hex digits is taken to be part of
350the hex escape (and then the lower 8 bits of the resulting hex number
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000351are used in 8-bit implementations).
Fred Drakef6669171998-05-06 19:52:49 +0000352
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000353Unlike Standard \C{},
354all unrecognized escape sequences are left in the string unchanged,
Fred Drake5c07d9b1998-05-14 19:37:06 +0000355i.e., \emph{the backslash is left in the string.} (This behavior is
Fred Drakef6669171998-05-06 19:52:49 +0000356useful when debugging: if an escape sequence is mistyped, the
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000357resulting output is more easily recognized as broken.)
Fred Drakef6669171998-05-06 19:52:49 +0000358\index{unrecognized escape sequence}
359
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000360When an `r' or `R' prefix is present, backslashes are still used to
361quote the following character, but \emph{all backslashes are left in
362the string}. For example, the string literal \code{r"\e n"} consists
363of two characters: a backslash and a lowercase `n'. String quotes can
364be escaped with a backslash, but the backslash remains in the string;
365for example, \code{r"\""} is a valid string literal consisting of two
366characters: a backslash and a double quote; \code{r"\"} is not a value
367string literal (even a raw string cannot end in an odd number of
368backslashes). Specifically, \emph{a raw string cannot end in a single
369backslash} (since the backslash would escape the following quote
370character).
371
372\subsection{String literal concatenation}
373
374Multiple adjacent string literals (delimited by whitespace), possibly
375using different quoting conventions, are allowed, and their meaning is
376the same as their concatenation. Thus, \code{"hello" 'world'} is
377equivalent to \code{"helloworld"}. This feature can be used to reduce
378the number of backslashes needed, to split long strings conveniently
379across long lines, or even to add comments to parts of strings, for
380example:
381
382\begin{verbatim}
383re.compile("[A-Za-z_]" # letter or underscore
384 "[A-Za-z0-9_]*" # letter, digit or underscore
385 )
386\end{verbatim}
387
388Note that this feature is defined at the syntactical level, but
389implemented at compile time. The `+' operator must be used to
390concatenate string expressions at run time. Also note that literal
391concatenation can use different quoting styles for each component
392(even mixing raw strings and triple quoted strings).
393
Fred Drakef6669171998-05-06 19:52:49 +0000394\subsection{Numeric literals}
395
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000396There are four types of numeric literals: plain integers, long
397integers, floating point numbers, and imaginary numbers. There are no
398complex literals (complex numbers can be formed by adding a real
399number and an imaginary number).
Fred Drakef6669171998-05-06 19:52:49 +0000400\index{number}
401\index{numeric literal}
402\index{integer literal}
403\index{plain integer literal}
404\index{long integer literal}
405\index{floating point literal}
406\index{hexadecimal literal}
407\index{octal literal}
408\index{decimal literal}
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000409\index{imaginary literal}
410\index{complex literal}
411
412Note that numeric literals do not include a sign; a phrase like
413\code{-1} is actually an expression composed of the unary operator
414`\code{-}' and the literal \code{1}.
415
416\subsection{Integer and long integer literals}
Fred Drakef6669171998-05-06 19:52:49 +0000417
418Integer and long integer literals are described by the following
419lexical definitions:
420
421\begin{verbatim}
422longinteger: integer ("l"|"L")
423integer: decimalinteger | octinteger | hexinteger
424decimalinteger: nonzerodigit digit* | "0"
425octinteger: "0" octdigit+
426hexinteger: "0" ("x"|"X") hexdigit+
Fred Drakef6669171998-05-06 19:52:49 +0000427nonzerodigit: "1"..."9"
428octdigit: "0"..."7"
429hexdigit: digit|"a"..."f"|"A"..."F"
430\end{verbatim}
431
432Although both lower case `l' and upper case `L' are allowed as suffix
433for long integers, it is strongly recommended to always use `L', since
434the letter `l' looks too much like the digit `1'.
435
436Plain integer decimal literals must be at most 2147483647 (i.e., the
437largest positive integer, using 32-bit arithmetic). Plain octal and
438hexadecimal literals may be as large as 4294967295, but values larger
439than 2147483647 are converted to a negative value by subtracting
4404294967296. There is no limit for long integer literals apart from
441what can be stored in available memory.
442
443Some examples of plain and long integer literals:
444
445\begin{verbatim}
4467 2147483647 0177 0x80000000
4473L 79228162514264337593543950336L 0377L 0x100000000L
448\end{verbatim}
449
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000450\subsection{Floating point literals}
451
Fred Drakef6669171998-05-06 19:52:49 +0000452Floating point literals are described by the following lexical
453definitions:
454
455\begin{verbatim}
456floatnumber: pointfloat | exponentfloat
457pointfloat: [intpart] fraction | intpart "."
458exponentfloat: (intpart | pointfloat) exponent
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000459intpart: nonzerodigit digit* | "0"
Fred Drakef6669171998-05-06 19:52:49 +0000460fraction: "." digit+
461exponent: ("e"|"E") ["+"|"-"] digit+
462\end{verbatim}
463
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000464Note that the integer part of a floating point number cannot look like
465an octal integer.
Fred Drakef6669171998-05-06 19:52:49 +0000466The allowed range of floating point literals is
467implementation-dependent.
Fred Drakef6669171998-05-06 19:52:49 +0000468Some examples of floating point literals:
469
470\begin{verbatim}
4713.14 10. .001 1e100 3.14e-10
472\end{verbatim}
473
474Note that numeric literals do not include a sign; a phrase like
Fred Drake5c07d9b1998-05-14 19:37:06 +0000475\code{-1} is actually an expression composed of the operator
476\code{-} and the literal \code{1}.
Fred Drakef6669171998-05-06 19:52:49 +0000477
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000478\subsection{Imaginary literals}
479
480Imaginary literals are described by the following lexical definitions:
481
482\begin{verbatim}
483imagnumber: (floatnumber | intpart) ("j"|"J")
484\end{verbatim}
485
486An imaginary literals yields a complex number with a real part of
4870.0. Complex numbers are represented as a pair of floating point
488numbers and have the same restrictions on their range. To create a
489complex number with a nonzero real part, add a floating point number
490to it, e.g. \code{(3+4j)}. Some examples of imaginary literals:
491
492\begin{verbatim}
4933.14j 10.j 10 j .001j 1e100j 3.14e-10j
494\end{verbatim}
495
496
Fred Drakef6669171998-05-06 19:52:49 +0000497\section{Operators}
498
499The following tokens are operators:
500\index{operators}
501
502\begin{verbatim}
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000503+ - * ** / %
Fred Drakef6669171998-05-06 19:52:49 +0000504<< >> & | ^ ~
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000505< > <= >= == != <>
Fred Drakef6669171998-05-06 19:52:49 +0000506\end{verbatim}
507
Fred Drake5c07d9b1998-05-14 19:37:06 +0000508The comparison operators \code{<>} and \code{!=} are alternate
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000509spellings of the same operator. \code{!=} is the preferred spelling;
510\code{<>} is obsolescent.
Fred Drakef6669171998-05-06 19:52:49 +0000511
512\section{Delimiters}
513
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000514The following tokens serve as delimiters in the grammar:
Fred Drakef6669171998-05-06 19:52:49 +0000515\index{delimiters}
516
517\begin{verbatim}
518( ) [ ] { }
Guido van Rossum60f2f0c1998-06-15 18:00:50 +0000519, : . ` = ;
520\end{verbatim}
521
522The period can also occur in floating-point and imaginary literals. A
523sequence of three periods has a special meaning as ellipses in slices.
524
525The following printing ASCII characters have special meaning as part
526of other tokens or are otherwise significant to the lexical analyzer:
527
528\begin{verbatim}
529' " # \
Fred Drakef6669171998-05-06 19:52:49 +0000530\end{verbatim}
531
532The following printing \ASCII{} characters are not used in Python. Their
533occurrence outside string literals and comments is an unconditional
534error:
Fred Drake5c07d9b1998-05-14 19:37:06 +0000535\index{ASCII@\ASCII{}}
Fred Drakef6669171998-05-06 19:52:49 +0000536
537\begin{verbatim}
538@ $ ?
539\end{verbatim}