blob: d6d4f56778d516d3f95c2d849b2ebce12847ad4e [file] [log] [blame]
Guido van Rossumf2612d11991-11-21 13:53:03 +00001% Format this file with latex.
2
3\documentstyle[myformat]{report}
4
5\title{\bf
6 Python Reference Manual \\
7 {\em Incomplete Draft}
8}
9
10\author{
11 Guido van Rossum \\
12 Dept. CST, CWI, Kruislaan 413 \\
13 1098 SJ Amsterdam, The Netherlands \\
14 E-mail: {\tt guido@cwi.nl}
15}
16
17\begin{document}
18
19\pagenumbering{roman}
20
21\maketitle
22
23\begin{abstract}
24
25\noindent
26Python is a simple, yet powerful programming language that bridges the
27gap between C and shell programming, and is thus ideally suited for
28``throw-away programming''
29and rapid prototyping. Its syntax is put
30together from constructs borrowed from a variety of other languages;
31most prominent are influences from ABC, C, Modula-3 and Icon.
32
33The Python interpreter is easily extended with new functions and data
34types implemented in C. Python is also suitable as an extension
35language for highly customizable C applications such as editors or
36window managers.
37
38Python is available for various operating systems, amongst which
39several flavors of {\UNIX}, Amoeba, the Apple Macintosh O.S.,
40and MS-DOS.
41
42This reference manual describes the syntax and ``core semantics'' of
43the language. It is terse, but exact and complete. The semantics of
44non-essential built-in object types and of the built-in functions and
Guido van Rossum4fc43bc1991-11-25 17:26:57 +000045modules are described in the {\em Python Library Reference}. For an
46informal introduction to the language, see the {\em Python Tutorial}.
Guido van Rossumf2612d11991-11-21 13:53:03 +000047
48\end{abstract}
49
50\pagebreak
51
52\tableofcontents
53
54\pagebreak
55
56\pagenumbering{arabic}
57
58\chapter{Introduction}
59
60This reference manual describes the Python programming language.
61It is not intended as a tutorial.
62
Guido van Rossum743d1e71992-01-07 16:43:53 +000063While I am trying to be as precise as possible, I chose to use English
64rather than formal specifications for everything except syntax and
65lexical analysis. This should make the document better understandable
66to the average reader, but will leave room for ambiguities.
67Consequently, if you were coming from Mars and tried to re-implement
68Python from this document alone, you might in fact be implementing
69quite a different language. On the other hand, if you are using
70Python and wonder what the precise rules about a particular area of
71the language are, you should be able to find it here.
72
73It is dangerous to add too many implementation details to a language
74reference document -- the implementation may change, and other
75implementations of the same language may work differently. On the
76other hand, there is currently only one Python implementation, and
77particular quirks of it are sometimes worth mentioning, especially
78where it differs from the ``ideal'' specification.
79
80Every Python implementation comes with a number of built-in and
81standard modules. These are not documented here, but in the separate
82{\em Python Library Reference} document. A few built-in modules are
83mentioned when they interact in a significant way with the language
84definition.
85
86\section{Notation}
87
88The descriptions of lexical analysis and syntax use a modified BNF
89grammar notation. This uses the following style of definition:
90
91\begin{verbatim}
92name: lcletter (lcletter | "_")*
93lcletter: "a"..."z"
94\end{verbatim}
95
96The first line says that a \verb\name\ is a \verb\lcletter\ followed by
97a sequence of zero or more \verb\lcletter\s and underscores. A
98\verb\lcletter\ in turn is any of the single characters `a' through `z'.
99(This rule is actually adhered to for the names defined in syntax and
100grammar rules in this document.)
101
102Each rule begins with a name (which is the name defined by the rule)
103followed by a colon. Each rule is wholly contained on one line. A
104vertical bar (\verb\|\) is used to separate alternatives, it is the
105least binding operator in this notation. A star (\verb\*\) means zero
106or more repetitions of the preceding item; likewise, a plus (\verb\+\)
107means one or more repetitions and a question mark (\verb\?\) zero or
108one (in other words, the preceding item is optional). These three
109operators bind as tight as possible; parentheses are used for
110grouping. Literal strings are enclosed in double quotes. White space
111is only meaningful to separate tokens.
112
113In lexical definitions (as the example above), two more conventions
114are used: Two literal characters separated by three dots mean a choice
115of any single character in the given (inclusive) range of ASCII
116characters. A phrase between angular brackets (\verb\<...>\) gives an
117informal description of the symbol defined; e.g., this could be used
118to describe the notion of `control character' if needed.
119
120Although the notation used is almost the same, there is a big
121difference between the meaning of lexical and syntactic definitions:
122a lexical definition operates on the individual characters of the
123input source, while a syntax definition operates on the stream of
124tokens generated by the lexical analysis.
125
Guido van Rossumf2612d11991-11-21 13:53:03 +0000126\chapter{Lexical analysis}
127
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000128A Python program is read by a {\em parser}. Input to the parser is a
129stream of {\em tokens}, generated by the {\em lexical analyzer}. This
130chapter describes how the lexical analyzer breaks a file into tokens.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000131
132\section{Line structure}
133
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000134A Python program is divided in a number of logical lines. Statements
135do not straddle logical line boundaries except where explicitly
136indicated by the syntax (i.e., for compound statements). To this
137purpose, the end of a logical line is represented by the token
138NEWLINE.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000139
140\subsection{Comments}
141
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000142A comment starts with a hash character (\verb\#\) that is not part of
143a string literal, and ends at the end of the physical line. Comments
144are ignored by the syntax.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000145
146\subsection{Line joining}
147
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000148Two or more physical lines may be joined into logical lines using
149backslash characters (\verb/\/), as follows: When physical line ends
150in a backslash that is not part of a string literal or comment, it is
151joined with the following forming a single logical line, deleting the
152backslash and the following end-of-line character.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000153
154\subsection{Blank lines}
155
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000156A logical line that contains only spaces, tabs, and possibly a
157comment, is ignored (i.e., no NEWLINE token is generated), except that
158during interactive input of statements, an entirely blank logical line
159terminates a multi-line statement.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000160
161\subsection{Indentation}
162
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000163Spaces and tabs at the beginning of a logical line are used to compute
Guido van Rossumf2612d11991-11-21 13:53:03 +0000164the indentation level of the line, which in turn is used to determine
165the grouping of statements.
166
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000167First, each tab is replaced by one to eight spaces such that the total
168number of spaces up to that point is a multiple of eight. The total
169number of spaces preceding the first non-blank character then
170determines the line's indentation. Indentation cannot be split over
171multiple physical lines using backslashes.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000172
173The indentation levels of consecutive lines are used to generate
174INDENT and DEDENT tokens, using a stack, as follows.
175
176Before the first line of the file is read, a single zero is pushed on
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000177the stack; this will never be popped off again. The numbers pushed on
178the stack will always be strictly increasing from bottom to top. At
179the beginning of each logical line, the line's indentation level is
180compared to the top of the stack. If it is equal, nothing happens.
181If it larger, it is pushed on the stack, and one INDENT token is
182generated. If it is smaller, it {\em must} be one of the numbers
183occurring on the stack; all numbers on the stack that are larger are
184popped off, and for each number popped off a DEDENT token is
185generated. At the end of the file, a DEDENT token is generated for
186each number remaining on the stack that is larger than zero.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000187
188\section{Other tokens}
189
190Besides NEWLINE, INDENT and DEDENT, the following categories of tokens
191exist: identifiers, keywords, literals, operators, and delimiters.
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000192Spaces and tabs are not tokens, but serve to delimit tokens. Where
193ambiguity exists, a token comprises the longest possible string that
194forms a legal token, when read from left to right.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000195
Guido van Rossumf2612d11991-11-21 13:53:03 +0000196\section{Identifiers}
197
198Identifiers are described by the following regular expressions:
199
200\begin{verbatim}
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000201identifier: (letter|"_") (letter|digit|"_")*
Guido van Rossumf2612d11991-11-21 13:53:03 +0000202letter: lowercase | uppercase
Guido van Rossum743d1e71992-01-07 16:43:53 +0000203lowercase: "a"..."z"
204uppercase: "A"..."Z"
205digit: "0"..."9"
Guido van Rossumf2612d11991-11-21 13:53:03 +0000206\end{verbatim}
207
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000208Identifiers are unlimited in length. Case is significant.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000209
210\section{Keywords}
211
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000212The following identifiers are used as reserved words, or {\em
213keywords} of the language, and may not be used as ordinary
214identifiers. They must be spelled exactly as written here:
Guido van Rossumf2612d11991-11-21 13:53:03 +0000215
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000216\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000217and del for in print
218break elif from is raise
219class else global not return
220continue except if or try
221def finally import pass while
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000222\end{verbatim}
223
Guido van Rossum743d1e71992-01-07 16:43:53 +0000224% # This Python program sorts and formats the above table
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000225% import string
226% l = []
227% try:
228% while 1:
229% l = l + string.split(raw_input())
230% except EOFError:
231% pass
232% l.sort()
233% for i in range((len(l)+4)/5):
234% for j in range(i, len(l), 5):
235% print string.ljust(l[j], 10),
236% print
Guido van Rossumf2612d11991-11-21 13:53:03 +0000237
238\section{Literals}
239
240\subsection{String literals}
241
242String literals are described by the following regular expressions:
243
244\begin{verbatim}
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000245stringliteral: "'" stringitem* "'"
Guido van Rossumf2612d11991-11-21 13:53:03 +0000246stringitem: stringchar | escapeseq
Guido van Rossum743d1e71992-01-07 16:43:53 +0000247stringchar: <any ASCII character except newline or "\" or "'">
248escapeseq: "'" <any ASCII character except newline>
Guido van Rossumf2612d11991-11-21 13:53:03 +0000249\end{verbatim}
250
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000251String literals cannot span physical line boundaries. Escape
252sequences in strings are actually interpreted according to rules
253simular to those used by Standard C. The recognized escape sequences
254are:
255
256\begin{center}
257\begin{tabular}{|l|l|}
258\hline
259\verb/\\/ & Backslash (\verb/\/) \\
260\verb/\'/ & Single quote (\verb/'/) \\
261\verb/\a/ & ASCII Bell (BEL) \\
262\verb/\b/ & ASCII Backspace (BS) \\
263\verb/\E/ & ASCII Escape (ESC) \\
264\verb/\f/ & ASCII Formfeed (FF) \\
265\verb/\n/ & ASCII Linefeed (LF) \\
266\verb/\r/ & ASCII Carriage Return (CR) \\
267\verb/\t/ & ASCII Horizontal Tab (TAB) \\
268\verb/\v/ & ASCII Vertical Tab (VT) \\
269\verb/\/{\em ooo} & ASCII character with octal value {\em ooo} \\
Guido van Rossum743d1e71992-01-07 16:43:53 +0000270\verb/\x/{em xx...} & ASCII character with hex value {\em xx...} \\
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000271\hline
272\end{tabular}
273\end{center}
274
275For compatibility with in Standard C, up to three octal digits are
276accepted, but an unlimited number of hex digits is taken to be part of
277the hex escape (and then the lower 8 bits of the resulting hex number
278are used...).
279
280All unrecognized escape sequences are left in the string {\em
281unchanged}, i.e., the backslash is left in the string. (This rule is
282useful when debugging: if an escape sequence is mistyped, the
Guido van Rossum743d1e71992-01-07 16:43:53 +0000283resulting output is more easily recognized as broken. It also helps a
284great deal for string literals used as regular expressions or
285otherwise passed to other modules that do their own escape handling --
286but you may end up quadrupling backslashes that must appear literally.)
Guido van Rossumf2612d11991-11-21 13:53:03 +0000287
288\subsection{Numeric literals}
289
290There are three types of numeric literals: integers, long integers,
291and floating point numbers.
292
293Integers and long integers are described by the following regular expressions:
294
295\begin{verbatim}
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000296longinteger: integer ("l"|"L")
Guido van Rossumf2612d11991-11-21 13:53:03 +0000297integer: decimalinteger | octinteger | hexinteger
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000298decimalinteger: nonzerodigit digit* | "0"
299octinteger: "0" octdigit+
300hexinteger: "0" ("x"|"X") hexdigit+
Guido van Rossumf2612d11991-11-21 13:53:03 +0000301
Guido van Rossum743d1e71992-01-07 16:43:53 +0000302nonzerodigit: "1"..."9"
303octdigit: "0"..."7"
304hexdigit: digit|"a"..."f"|"A"..."F"
Guido van Rossumf2612d11991-11-21 13:53:03 +0000305\end{verbatim}
306
307Floating point numbers are described by the following regular expressions:
308
309\begin{verbatim}
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000310floatnumber: [intpart] fraction [exponent] | intpart ["."] exponent
Guido van Rossumf2612d11991-11-21 13:53:03 +0000311intpart: digit+
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000312fraction: "." digit+
313exponent: ("e"|"E") ["+"|"-"] digit+
Guido van Rossumf2612d11991-11-21 13:53:03 +0000314\end{verbatim}
315
316\section{Operators}
317
318The following tokens are operators:
319
320\begin{verbatim}
321+ - * / %
322<< >> & | ^ ~
Guido van Rossum743d1e71992-01-07 16:43:53 +0000323< == > <= <> != >=
Guido van Rossumf2612d11991-11-21 13:53:03 +0000324\end{verbatim}
325
Guido van Rossum743d1e71992-01-07 16:43:53 +0000326The comparison operators \verb\<>\ and \verb\!=\ are alternate
327spellings of the same operator.
328
Guido van Rossumf2612d11991-11-21 13:53:03 +0000329\section{Delimiters}
330
Guido van Rossum743d1e71992-01-07 16:43:53 +0000331The following tokens serve as delimiters or otherwise have a special
332meaning:
Guido van Rossumf2612d11991-11-21 13:53:03 +0000333
334\begin{verbatim}
335( ) [ ] { }
Guido van Rossum743d1e71992-01-07 16:43:53 +0000336; , : . ` =
Guido van Rossumf2612d11991-11-21 13:53:03 +0000337\end{verbatim}
338
339The following printing ASCII characters are currently not used;
340their occurrence is an unconditional error:
341
342\begin{verbatim}
343! @ $ " ?
344\end{verbatim}
345
346\chapter{Execution model}
347
Guido van Rossum743d1e71992-01-07 16:43:53 +0000348(XXX This chapter should explain the general model of the execution of
349Python code and the evaluation of expressions. It should introduce
350objects, values, code blocks, scopes, name spaces, name binding,
351types, sequences, numbers, mappings, exceptions, and other technical
352terms needed to make the following chapters concise and exact.)
353
354\section{Objects, values and types}
355
356I won't try to define rigorously here what an object is, but I'll give
357some properties of objects that are important to know about.
358
359Every object has an identity, a type and a value. An object's {\em
360identity} never changes once it has been created; think of it as the
361object's (permanent) address. An object's {\em type} determines the
362operations that an object supports (e.g., can its length be taken?)
363and also defines the ``meaning'' of the object's value; it also never
364changes. The {\em value} of some objects can change; whether an
365object's value can change is a property of its type.
366
367Objects are never explicitly destroyed; however, when they become
368unreachable they may be garbage-collected. An implementation,
369however, is allowed to delay garbage collection or omit it altogether
370-- it is a matter of implementation quality how garbage collection is
371implemented. (Implementation note: the current implementation uses a
372reference-counting scheme which collects most objects as soon as they
373become onreachable, but does not detect garbage containing circular
374references.)
375
376(Some objects contain references to ``external'' resources such as
377open files. It is understood that these resources are freed when the
378object is garbage-collected, but since garbage collection is not
379guaranteed such objects also provide an explicit way to release the
380external resource (e.g., a \verb\close\ method) and programs are
381recommended to use this.)
382
383Some objects contain references to other objects. These references
384are part of the object's value; in most cases, when such a
385``container'' object is compared to another (of the same type), the
386comparison takes the {\em values} of the referenced objects into
387account (not their identities).
388
389Except for their identity, types affect almost any aspect of objects.
390Even object identities are affected in some sense: for immutable
391types, operations that compute new values may actually return a
392reference to an existing object with the same type and value, while
393for mutable objects this is not allowed. E.g., after
394
395\begin{verbatim}
396a = 1; b = 1; c = []; d = []
397\end{verbatim}
398
399\verb\a\ and \verb\b\ may or may not refer to the same object, but
400\verb\c\ and \verb\d\ are guaranteed to refer to two different, unique,
401newly created lists.
402
403\section{Execution frames, name spaces, and scopes}
404
405XXX
Guido van Rossumf2612d11991-11-21 13:53:03 +0000406
407\chapter{Expressions and conditions}
408
Guido van Rossum743d1e71992-01-07 16:43:53 +0000409From now on, extended BNF notation will be used to describe syntax,
410not lexical analysis.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000411
412This chapter explains the meaning of the elements of expressions and
413conditions. Conditions are a superset of expressions, and a condition
414may be used where an expression is required by enclosing it in
Guido van Rossum743d1e71992-01-07 16:43:53 +0000415parentheses. The only place where an unparenthesized condition is not
416allowed is on the right-hand side of the assignment operator, because
417this operator is the same token (\verb\=\) as used for compasisons.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000418
Guido van Rossum743d1e71992-01-07 16:43:53 +0000419The comma plays a somewhat special role in Python's syntax. It is an
420operator with a lower precedence than all others, but occasionally
421serves other purposes as well (e.g., it has special semantics in print
422statements). When a comma is accepted by the syntax, one of the
423syntactic categories \verb\expression_list\ or \verb\condition_list\
424is always used.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000425
426When (one alternative of) a syntax rule has the form
427
428\begin{verbatim}
429name: othername
430\end{verbatim}
431
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000432and no semantics are given, the semantics of this form of \verb\name\
433are the same as for \verb\othername\.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000434
435\section{Arithmetic conversions}
436
437When a description of an arithmetic operator below uses the phrase
438``the numeric arguments are converted to a common type'',
439this both means that if either argument is not a number, a
440{\tt TypeError} exception is raised, and that otherwise
441the following conversions are applied:
442
443\begin{itemize}
444\item First, if either argument is a floating point number,
445 the other is converted to floating point;
446\item else, if either argument is a long integer,
447 the other is converted to long integer;
448\item otherwise, both must be short integers and no conversion
449 is necessary.
450\end{itemize}
451
452(Note: ``short integers'' in Python are at least 32 bits in size;
453``long integers'' are arbitrary precision integers.)
454
455\section{Atoms}
456
457Atoms are the most basic elements of expressions.
458Forms enclosed in reverse quotes or various types of parentheses
459or braces are also categorized syntactically as atoms.
460Syntax rules for atoms:
461
462\begin{verbatim}
463atom: identifier | literal | parenth_form | string_conversion
464literal: stringliteral | integer | longinteger | floatnumber
465parenth_form: enclosure | list_display | dict_display
Guido van Rossum743d1e71992-01-07 16:43:53 +0000466enclosure: "(" [condition_list] ")"
467list_display: "[" [condition_list] "]"
468dict_display: "{" [key_datum ("," key_datum)* [","] "}"
469key_datum: condition ":" condition
470string_conversion:"`" condition_list "`"
Guido van Rossumf2612d11991-11-21 13:53:03 +0000471\end{verbatim}
472
473\subsection{Identifiers (Names)}
474
475An identifier occurring as an atom is a reference to a local, global
476or built-in name binding. If a name can be assigned to anywhere in a code
477block, it refers to a local name throughout that code block.
478Otherwise, it refers to a global name if one exists, else to a
479built-in name.
480
481When the name is bound to an object, evaluation of the atom
482yields that object.
483When it is not bound, a {\tt NameError} exception
484is raised, with the identifier as string parameter.
485
486\subsection{Literals}
487
488Evaluation of a literal yields an object of the given type
489(string, integer, long integer, floating point number)
490with the given value.
491The value may be approximated in the case of floating point literals.
492
493All literals correspond to immutable data types, and hence the object's
494identity is less important than its value.
495Multiple evaluations of the same literal (either the same occurrence
496in the program text or a different occurrence) may
497obtain the same object or a different object with the same value.
498
499(In the original implementation, all literals in the same code block
500with the same type and value yield the same object.)
501
502\subsection{Enclosures}
503
504An empty enclosure yields an empty tuple object.
505
506An enclosed condition list yields whatever that condition list yields.
507
508(Note that, except for empty tuples, tuples are not formed by
509enclosure in parentheses, but rather by use of the comma operator.)
510
511\subsection{List displays}
512
513A list display yields a new list object.
514
515If it has no condition list, the list object has no items.
516Otherwise, the elements of the condition list are evaluated
517from left to right and inserted in the list object in that order.
518
519\subsection{Dictionary displays}
520
521A dictionary display yields a new dictionary object.
522
523The key/datum pairs are evaluated from left to right to
524define the entries of the dictionary:
525each key object is used as a key into the dictionary to store
526the corresponding datum pair.
527
Guido van Rossum743d1e71992-01-07 16:43:53 +0000528Keys must be strings, otherwise a {\tt TypeError} exception is raised.
529Clashes between keys are not detected; the last datum (textually
530rightmost in the display) stored for a given key value prevails.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000531
532\subsection{String conversions}
533
534A string conversion evaluates the contained condition list and converts the
535resulting object into a string according to rules specific to its type.
536
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000537If the object is a string, a number, \verb\None\, or a tuple, list or
Guido van Rossumf2612d11991-11-21 13:53:03 +0000538dictionary containing only objects whose type is in this list,
539the resulting
540string is a valid Python expression which can be passed to the
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000541built-in function \verb\eval()\ to yield an expression with the
Guido van Rossumf2612d11991-11-21 13:53:03 +0000542same value (or an approximation, if floating point numbers are
543involved).
544
545(In particular, converting a string adds quotes around it and converts
546``funny'' characters to escape sequences that are safe to print.)
547
548It is illegal to attempt to convert recursive objects (e.g.,
549lists or dictionaries that -- directly or indirectly -- contain a reference
550to themselves.)
551
552\section{Primaries}
553
554Primaries represent the most tightly bound operations of the language.
555Their syntax is:
556
557\begin{verbatim}
558primary: atom | attributeref | call | subscription | slicing
Guido van Rossum743d1e71992-01-07 16:43:53 +0000559attributeref: primary "." identifier
560call: primary "(" [condition_list] ")"
561subscription: primary "[" condition "]"
562slicing: primary "[" [condition] ":" [condition] "]"
Guido van Rossumf2612d11991-11-21 13:53:03 +0000563\end{verbatim}
564
565\subsection{Attribute references}
566
567\subsection{Calls}
568
569\subsection{Subscriptions}
570
571\subsection{Slicings}
572
573\section{Factors}
574
575Factors represent the unary numeric operators.
576Their syntax is:
577
578\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000579factor: primary | "-" factor | "+" factor | "~" factor
Guido van Rossumf2612d11991-11-21 13:53:03 +0000580\end{verbatim}
581
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000582The unary \verb\-\ operator yields the negative of its numeric argument.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000583
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000584The unary \verb\+\ operator yields its numeric argument unchanged.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000585
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000586The unary \verb\~\ operator yields the bit-wise negation of its
Guido van Rossumf2612d11991-11-21 13:53:03 +0000587integral numerical argument.
588
589In all three cases, if the argument does not have the proper type,
590a {\tt TypeError} exception is raised.
591
592\section{Terms}
593
594Terms represent the most tightly binding binary operators:
595
596\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000597term: factor | term "*" factor | term "/" factor | term "%" factor
Guido van Rossumf2612d11991-11-21 13:53:03 +0000598\end{verbatim}
599
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000600The \verb\*\ operator yields the product of its arguments.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000601The arguments must either both be numbers, or one argument must be
602a (short) integer and the other must be a string.
603In the former case, the numbers are converted to a common type
604and then multiplied together.
605In the latter case, string repetition is performed; a negative
606repetition factor yields the empty string.
607
Guido van Rossum743d1e71992-01-07 16:43:53 +0000608The \verb|"/"| operator yields the quotient of its arguments.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000609The numeric arguments are first converted to a common type.
610(Short or long) integer division yields an integer of the same type,
611truncating towards zero.
612Division by zero raises a {\tt RuntimeError} exception.
613
Guido van Rossum743d1e71992-01-07 16:43:53 +0000614The \verb|"%"| operator yields the remainder from the division
Guido van Rossumf2612d11991-11-21 13:53:03 +0000615of the first argument by the second.
616The numeric arguments are first converted to a common type.
Guido van Rossum47f23331991-12-06 17:21:05 +0000617The outcome of $x \% y$ is defined as $x - y*trunc(x/y)$.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000618A zero right argument raises a {\tt RuntimeError} exception.
619The arguments may be floating point numbers, e.g.,
Guido van Rossum47f23331991-12-06 17:21:05 +0000620$3.14 \% 0.7$ equals $0.34$.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000621
622\section{Arithmetic expressions}
623
624\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000625arith_expr: term | arith_expr "+" term | arith_expr "-" term
Guido van Rossumf2612d11991-11-21 13:53:03 +0000626\end{verbatim}
627
Guido van Rossum743d1e71992-01-07 16:43:53 +0000628The \verb|"+"| operator yields the sum of its arguments.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000629The arguments must either both be numbers, or both strings.
630In the former case, the numbers are converted to a common type
631and then added together.
632In the latter case, the strings are concatenated directly,
633without inserting a space.
634
Guido van Rossum743d1e71992-01-07 16:43:53 +0000635The \verb|"-"| operator yields the difference of its arguments.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000636The numeric arguments are first converted to a common type.
637
638\section{Shift expressions}
639
640\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000641shift_expr: arith_expr | shift_expr "<<" arith_expr | shift_expr ">>" arith_expr
Guido van Rossumf2612d11991-11-21 13:53:03 +0000642\end{verbatim}
643
644These operators accept short integers as arguments only.
645They shift their left argument to the left or right by the number of bits
Guido van Rossum743d1e71992-01-07 16:43:53 +0000646given by the right argument. Shifts are ``logical"", e.g., bits shifted
Guido van Rossumf2612d11991-11-21 13:53:03 +0000647out on one end are lost, and bits shifted in are zero;
648negative numbers are shifted as if they were unsigned in C.
649Negative shift counts and shift counts greater than {\em or equal to}
650the word size yield undefined results.
651
652\section{Bitwise AND expressions}
653
654\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000655and_expr: shift_expr | and_expr "&" shift_expr
Guido van Rossumf2612d11991-11-21 13:53:03 +0000656\end{verbatim}
657
658This operator yields the bitwise AND of its arguments,
659which must be short integers.
660
661\section{Bitwise XOR expressions}
662
663\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000664xor_expr: and_expr | xor_expr "^" and_expr
Guido van Rossumf2612d11991-11-21 13:53:03 +0000665\end{verbatim}
666
667This operator yields the bitwise exclusive OR of its arguments,
668which must be short integers.
669
670\section{Bitwise OR expressions}
671
672\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000673or_expr: xor_expr | or_expr "|" xor_expr
Guido van Rossumf2612d11991-11-21 13:53:03 +0000674\end{verbatim}
675
676This operator yields the bitwise OR of its arguments,
677which must be short integers.
678
679\section{Expressions and expression lists}
680
681\begin{verbatim}
682expression: or_expression
Guido van Rossum743d1e71992-01-07 16:43:53 +0000683expr_list: expression ("," expression)* [","]
Guido van Rossumf2612d11991-11-21 13:53:03 +0000684\end{verbatim}
685
686An expression list containing at least one comma yields a new tuple.
687The length of the tuple is the number of expressions in the list.
688The expressions are evaluated from left to right.
689
690The trailing comma is required only to create a single tuple;
691it is optional in all other cases (a single expression without
692a trailing comma doesn't create a tuple, but rather yields the
693value of that expression).
694
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000695To create an empty tuple, use an empty pair of parentheses: \verb\()\.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000696
697\section{Comparisons}
698
699\begin{verbatim}
700comparison: expression (comp_operator expression)*
Guido van Rossum743d1e71992-01-07 16:43:53 +0000701comp_operator: "<"|">"|"=="|">="|"<="|"<>"|"!="|"is" ["not"]|["not"] "in"
Guido van Rossumf2612d11991-11-21 13:53:03 +0000702\end{verbatim}
703
704Comparisons yield integer value: 1 for true, 0 for false.
705
706Comparisons can be chained arbitrarily,
707e.g., $x < y <= z$ is equivalent to
708$x < y$ {\tt and} $y <= z$, except that $y$ is evaluated only once
709(but in both cases $z$ is not evaluated at all when $x < y$ is
710found to be false).
711
712Formally, $e_0 op_1 e_1 op_2 e_2 ...e_{n-1} op_n e_n$ is equivalent to
713$e_0 op_1 e_1$ {\tt and} $e_1 op_2 e_2$ {\tt and} ... {\tt and}
714$e_{n-1} op_n e_n$, except that each expression is evaluated at most once.
715
716Note that $e_0 op_1 e_1 op_2 e_2$ does not imply any kind of comparison
717between $e_0$ and $e_2$, e.g., $x < y > z$ is perfectly legal.
718
Guido van Rossum743d1e71992-01-07 16:43:53 +0000719The forms \verb\<>\ and \verb\!=\ are equivalent.
Guido van Rossumf2612d11991-11-21 13:53:03 +0000720
Guido van Rossum743d1e71992-01-07 16:43:53 +0000721The operators {\tt "<", ">", "==", ">=", "<="}, and {\tt "<>"} compare
Guido van Rossumf2612d11991-11-21 13:53:03 +0000722the values of two objects. The objects needn't have the same type.
723If both are numbers, they are compared to a common type.
724Otherwise, objects of different types {\em always} compare unequal,
725and are ordered consistently but arbitrarily, except that
726the value \verb\None\ compares smaller than the values of any other type.
727
728(This unusual
729definition of comparison is done to simplify the definition of
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000730operations like sorting and the \verb\in\ and \verb\not in\ operators.)
Guido van Rossumf2612d11991-11-21 13:53:03 +0000731
732Comparison of objects of the same type depends on the type:
733
734\begin{itemize}
735\item Numbers are compared arithmetically.
736\item Strings are compared lexicographically using the numeric
737 equivalents (the result of the built-in function ord())
738 of their characters.
739\item Tuples and lists are compared lexicographically
740 using comparison of corresponding items.
741\item Dictionaries compare unequal unless they are the same object;
742 the choice whether one dictionary object is considered smaller
743 or larger than another one is made arbitrarily but
744 consistently within one execution of a program.
745\item The latter rule is also used for most other built-in types.
746\end{itemize}
747
748The operators \verb\in\ and \verb\not in\ test for sequence membership:
749if $y$ is a sequence, $x {\tt in} y$ is true if and only if there exists
750an index $i$ such that $x = y_i$.
751$x {\tt not in} y$ yields the inverse truth value.
752The exception {\tt TypeError} is raised when $y$ is not a sequence,
753or when $y$ is a string and $x$ is not a string of length one.
754
755The operators \verb\is\ and \verb\is not\ compare object identity:
756$x {\tt is} y$ is true if and only if $x$ and $y$ are the same object.
757$x {\tt is not} y$ yields the inverse truth value.
758
759\section{Boolean operators}
760
761\begin{verbatim}
762condition: or_test
Guido van Rossum743d1e71992-01-07 16:43:53 +0000763or_test: and_test | or_test "or" and_test
764and_test: not_test | and_test "and" not_test
765not_test: comparison | "not" not_test
Guido van Rossumf2612d11991-11-21 13:53:03 +0000766\end{verbatim}
767
768In the context of Boolean operators, and also when conditions are
769used by control flow statements, the following values are interpreted
770as false: None, numeric zero of all types, empty sequences (strings,
771tuples and lists), and empty mappings (dictionaries).
772All other values are interpreted as true.
773
774The operator \verb\not\ yields 1 if its argument is false, 0 otherwise.
775
776The condition $x {\tt and} y$ first evaluates $x$; if $x$ is false,
777$x$ is returned; otherwise, $y$ is evaluated and returned.
778
779The condition $x {\tt or} y$ first evaluates $x$; if $x$ is true,
780$x$ is returned; otherwise, $y$ is evaluated and returned.
781
782(Note that \verb\and\ and \verb\or\ do not restrict the value and type
783they return to 0 and 1, but rather return the last evaluated argument.
784This is sometimes useful, e.g., if $s$ is a string, which should be
785replaced by a default value if it is empty, $s {\tt or} 'foo'$
786returns the desired value. Because \verb\not\ has to invent a value
787anyway, it does not bother to return a value of the same type as its
788argument, so \verb\not 'foo'\ yields $0$, not $''$.)
789
790\chapter{Simple statements}
791
792Simple statements are comprised within a single logical line.
793Several simple statements may occor on a single line separated
794by semicolons. The syntax for simple statements is:
795
796\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000797stmt_list: simple_stmt (";" simple_stmt)* [";"]
Guido van Rossumf2612d11991-11-21 13:53:03 +0000798simple_stmt: expression_stmt
799 | assignment
800 | pass_stmt
801 | del_stmt
802 | print_stmt
803 | return_stmt
804 | raise_stmt
805 | break_stmt
806 | continue_stmt
807 | import_stmt
Guido van Rossum743d1e71992-01-07 16:43:53 +0000808 | global_stmt
Guido van Rossumf2612d11991-11-21 13:53:03 +0000809\end{verbatim}
810
811\section{Expression statements}
812
813\begin{verbatim}
814expression_stmt: expression_list
815\end{verbatim}
816
817An expression statement evaluates the expression list (which may
818be a single expression).
819If the value is not \verb\None\, it is converted to a string
820using the rules for string conversions, and the resulting string
821is written to standard output on a line by itself.
822
823(The exception for \verb\None\ is made so that procedure calls,
824which are syntactically equivalent to expressions,
825do not cause any output.)
826
827\section{Assignments}
828
829\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000830assignment: target_list ("=" target_list)* "=" expression_list
831target_list: target ("," target)* [","]
832target: identifier | "(" target_list ")" | "[" target_list "]"
Guido van Rossumf2612d11991-11-21 13:53:03 +0000833 | attributeref | subscription | slicing
834\end{verbatim}
835
836(See the section on primaries for the definition of the last
837three symbols.)
838
839An assignment evaluates the expression list (remember that this can
840be a single expression or a comma-separated list,
841the latter yielding a tuple)
842and assigns the single resulting object to each of the target lists,
843from left to right.
844
845Assignment is defined recursively depending on the type of the
846target. Where assignment is to part of a mutable object
847(through an attribute reference, subscription or slicing),
848the mutable object must ultimately perform the
849assignment and decide about its validity, raising an exception
850if the assignment is unacceptable. The rules observed by
851various types and the exceptions raised are given with the
852definition of the object types (some of which are defined
853in the library reference).
854
855Assignment of an object to a target list is recursively
856defined as follows.
857
858\begin{itemize}
859\item
860If the target list contains no commas (except in nested constructs):
861the object is assigned to the single target contained in the list.
862
863\item
864If the target list contains commas (that are not in nested constructs):
865the object must be a tuple with as many items
866as the list contains targets, and the items are assigned, from left
867to right, to the corresponding targets.
868
869\end{itemize}
870
871Assignment of an object to a (non-list)
872target is recursively defined as follows.
873
874\begin{itemize}
875
876\item
877If the target is an identifier (name):
878the object is bound to that name
879in the current local scope. Any previous binding of the same name
880is undone.
881
882\item
883If the target is a target list enclosed in parentheses:
884the object is assigned to that target list.
885
886\item
887If the target is a target list enclosed in square brackets:
888the object must be a list with as many items
889as the target list contains targets,
890and the list's items are assigned, from left to right,
891to the corresponding targets.
892
893\item
894If the target is an attribute reference:
895The primary expression in the reference is evaluated.
896It should yield an object with assignable attributes;
897if this is not the case, a {\tt TypeError} exception is raised.
898That object is then asked to assign the assigned object
899to the given attribute; if it cannot perform the assignment,
900it raises an exception.
901
902\item
903If the target is a subscription:
904The primary expression in the reference is evaluated.
905It should yield either a mutable sequence object or a mapping
906(dictionary) object.
907Next, the subscript expression is evaluated.
908
909If the primary is a sequence object, the subscript must yield a
910nonnegative integer smaller than the sequence's length,
911and the sequence is asked to assign the assigned object
912to its item with that index.
913
914If the primary is a mapping object, the subscript must have a
915type compatible with the mapping's key type,
916and the mapping is then asked to to create a key/datum pair
917which maps the subscript to the assigned object.
918
919Various exceptions can be raised.
920
921\item
922If the target is a slicing:
923The primary expression in the reference is evaluated.
924It should yield a mutable sequence object (currently only lists).
925The assigned object should be a sequence object of the same type.
926Next, the lower and upper bound expressions are evaluated,
927insofar they are present; defaults are zero and the sequence's length.
928The bounds should evaluate to (small) integers.
929If either bound is negative, the sequence's length is added to it (once).
930The resulting bounds are clipped to lie between zero
931and the sequence's length, inclusive.
932(XXX Shouldn't this description be with expressions?)
933Finally, the sequence object is asked to replace the items
934indicated by the slice with the items of the assigned sequence.
935This may change the sequence's length, if it allows it.
936
937\end{itemize}
938
939(In the original implementation, the syntax for targets is taken
940to be the same as for expressions, and invalid syntax is rejected
941during the code generation phase, causing less detailed error
942messages.)
943
944\section{The {\tt pass} statement}
945
946\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000947pass_stmt: "pass"
Guido van Rossumf2612d11991-11-21 13:53:03 +0000948\end{verbatim}
949
950{\tt pass} is a null operation -- when it is executed,
951nothing happens.
952
953\section{The {\tt del} statement}
954
955\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000956del_stmt: "del" target_list
Guido van Rossumf2612d11991-11-21 13:53:03 +0000957\end{verbatim}
958
959Deletion is recursively defined similar to assignment.
960
961(XXX Rather that spelling it out in full details,
962here are some hints.)
963
964Deletion of a target list recursively deletes each target,
965from left to right.
966
967Deletion of a name removes the binding of that name (which must exist)
968from the local scope.
969
970Deletion of attribute references, subscriptions and slicings
971is passed to the primary object involved; deletion of a slicing
972is in general equivalent to assignment of an empty slice of the
973right type (but even this is determined by the sliced object).
974
975\section{The {\tt print} statement}
976
977\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +0000978print_stmt: "print" [ condition ("," condition)* [","] ]
Guido van Rossumf2612d11991-11-21 13:53:03 +0000979\end{verbatim}
980
981{\tt print} evaluates each condition in turn and writes the resulting
982object to standard output (see below).
983If an object is not a string, it is first converted to
984a string using the rules for string conversions.
985The (resulting or original) string is then written.
986A space is written before each object is (converted and) written,
987unless the output system believes it is positioned at the beginning
988of a line. This is the case: (1) when no characters have been written
989to standard output; or (2) when the last character written to
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000990standard output is \verb/\n/;
Guido van Rossumf2612d11991-11-21 13:53:03 +0000991or (3) when the last I/O operation
992on standard output was not a \verb\print\ statement.
993
994Finally,
Guido van Rossum4fc43bc1991-11-25 17:26:57 +0000995a \verb/\n/ character is written at the end,
Guido van Rossumf2612d11991-11-21 13:53:03 +0000996unless the \verb\print\ statement ends with a comma.
997This is the only action if the statement contains just the keyword
998\verb\print\.
999
1000Standard output is defined as the file object named \verb\stdout\
1001in the built-in module \verb\sys\. If no such object exists,
1002or if it is not a writable file, a {\tt RuntimeError} exception is raised.
1003(The original implementation attempts to write to the system's original
1004standard output instead, but this is not safe, and should be fixed.)
1005
1006\section{The {\tt return} statement}
1007
1008\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +00001009return_stmt: "return" [condition_list]
Guido van Rossumf2612d11991-11-21 13:53:03 +00001010\end{verbatim}
1011
1012\verb\return\ may only occur syntactically nested in a function
1013definition, not within a nested class definition.
1014
1015If a condition list is present, it is evaluated, else \verb\None\
1016is substituted.
1017
1018\verb\return\ leaves the current function call with the condition
1019list (or \verb\None\) as return value.
1020
1021When \verb\return\ passes control out of a \verb\try\ statement
1022with a \verb\finally\ clause, that finally clause is executed
1023before really leaving the function.
1024(XXX This should be made more exact, a la Modula-3.)
1025
1026\section{The {\tt raise} statement}
1027
1028\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +00001029raise_stmt: "raise" condition ["," condition]
Guido van Rossumf2612d11991-11-21 13:53:03 +00001030\end{verbatim}
1031
1032\verb\raise\ evaluates its first condition, which must yield
1033a string object. If there is a second condition, this is evaluated,
1034else \verb\None\ is substituted.
1035
1036It then raises the exception identified by the first object,
1037with the second one (or \verb\None\) as its parameter.
1038
1039\section{The {\tt break} statement}
1040
1041\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +00001042break_stmt: "break"
Guido van Rossumf2612d11991-11-21 13:53:03 +00001043\end{verbatim}
1044
1045\verb\break\ may only occur syntactically nested in a \verb\for\
1046or \verb\while\ loop, not nested in a function or class definition.
1047
1048It terminates the neares enclosing loop, skipping the optional
1049\verb\else\ clause if the loop has one.
1050
1051If a \verb\for\ loop is terminated by \verb\break\, the loop control
1052target (list) keeps its current value.
1053
1054When \verb\break\ passes control out of a \verb\try\ statement
1055with a \verb\finally\ clause, that finally clause is executed
1056before really leaving the loop.
1057
1058\section{The {\tt continue} statement}
1059
1060\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +00001061continue_stmt: "continue"
Guido van Rossumf2612d11991-11-21 13:53:03 +00001062\end{verbatim}
1063
1064\verb\continue\ may only occur syntactically nested in a \verb\for\
1065or \verb\while\ loop, not nested in a function or class definition,
1066and {\em not nested in a \verb\try\ statement with a \verb\finally\
1067clause}.
1068
1069It continues with the next cycle of the nearest enclosing loop.
1070
1071\section{The {\tt import} statement}
1072
1073\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +00001074import_stmt: "import" identifier ("," identifier)*
1075 | "from" identifier "import" identifier ("," identifier)*
1076 | "from" identifier "import" "*"
1077\end{verbatim}
1078
1079(XXX To be done.)
1080
1081\section{The {\tt global} statement}
1082
1083\begin{verbatim}
1084global_stmt: "global" identifier ("," identifier)*
Guido van Rossumf2612d11991-11-21 13:53:03 +00001085\end{verbatim}
1086
1087(XXX To be done.)
1088
1089\chapter{Compound statements}
1090
1091(XXX The semantic definitions of this chapter are still to be done.)
1092
1093\begin{verbatim}
1094statement: stmt_list NEWLINE | compound_stmt
1095compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
1096suite: statement | NEWLINE INDENT statement+ DEDENT
1097\end{verbatim}
1098
1099\section{The {\tt if} statement}
1100
1101\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +00001102if_stmt: "if" condition ":" suite
1103 ("elif" condition ":" suite)*
1104 ["else" ":" suite]
Guido van Rossumf2612d11991-11-21 13:53:03 +00001105\end{verbatim}
1106
1107\section{The {\tt while} statement}
1108
1109\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +00001110while_stmt: "while" condition ":" suite ["else" ":" suite]
Guido van Rossumf2612d11991-11-21 13:53:03 +00001111\end{verbatim}
1112
1113\section{The {\tt for} statement}
1114
1115\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +00001116for_stmt: "for" target_list "in" condition_list ":" suite
1117 ["else" ":" suite]
Guido van Rossumf2612d11991-11-21 13:53:03 +00001118\end{verbatim}
1119
1120\section{The {\tt try} statement}
1121
1122\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +00001123try_stmt: "try" ":" suite
1124 ("except" condition ["," condition] ":" suite)*
1125 ["finally" ":" suite]
Guido van Rossumf2612d11991-11-21 13:53:03 +00001126\end{verbatim}
1127
1128\section{Function definitions}
1129
1130\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +00001131funcdef: "def" identifier "(" [parameter_list] ")" ":" suite
1132parameter_list: parameter ("," parameter)*
1133parameter: identifier | "(" parameter_list ")"
Guido van Rossumf2612d11991-11-21 13:53:03 +00001134\end{verbatim}
1135
1136\section{Class definitions}
1137
1138\begin{verbatim}
Guido van Rossum743d1e71992-01-07 16:43:53 +00001139classdef: "class" identifier [inheritance] ":" suite
1140inheritance: "(" expression ("," expression)* ")"
Guido van Rossumf2612d11991-11-21 13:53:03 +00001141\end{verbatim}
1142
1143XXX Syntax for scripts, modules
1144XXX Syntax for interactive input, eval, exec, input
Guido van Rossum743d1e71992-01-07 16:43:53 +00001145XXX New definition of expressions (as conditions)
Guido van Rossumf2612d11991-11-21 13:53:03 +00001146
1147\end{document}