@@ -13,7 +13,7 @@ This chapter explains the meaning of the elements of expressions in Python.
13
13
be used to describe syntax, not lexical analysis. When (one alternative of) a
14
14
syntax rule has the form
15
15
16
- .. productionlist :: *
16
+ .. productionlist :: python-grammar
17
17
name: `othername `
18
18
19
19
and no semantics are given, the semantics of this form of ``name `` are the same
@@ -54,7 +54,7 @@ Atoms are the most basic elements of expressions. The simplest atoms are
54
54
identifiers or literals. Forms enclosed in parentheses, brackets or braces are
55
55
also categorized syntactically as atoms. The syntax for atoms is:
56
56
57
- .. productionlist ::
57
+ .. productionlist :: python-grammar
58
58
atom: `identifier ` | `literal ` | `enclosure `
59
59
enclosure: `parenth_form ` | `list_display ` | `dict_display ` | `set_display `
60
60
: | `generator_expression ` | `yield_atom `
@@ -103,7 +103,7 @@ Literals
103
103
104
104
Python supports string and bytes literals and various numeric literals:
105
105
106
- .. productionlist ::
106
+ .. productionlist :: python-grammar
107
107
literal: `stringliteral ` | `bytesliteral `
108
108
: | `integer ` | `floatnumber ` | `imagnumber `
109
109
@@ -134,7 +134,7 @@ Parenthesized forms
134
134
135
135
A parenthesized form is an optional expression list enclosed in parentheses:
136
136
137
- .. productionlist ::
137
+ .. productionlist :: python-grammar
138
138
parenth_form: "(" [`starred_expression `] ")"
139
139
140
140
A parenthesized expression list yields whatever that expression list yields: if
@@ -177,7 +177,7 @@ called "displays", each of them in two flavors:
177
177
178
178
Common syntax elements for comprehensions are:
179
179
180
- .. productionlist ::
180
+ .. productionlist :: python-grammar
181
181
comprehension: `assignment_expression ` `comp_for `
182
182
comp_for: ["async"] "for" `target_list ` "in" `or_test ` [`comp_iter `]
183
183
comp_iter: `comp_for ` | `comp_if `
@@ -243,7 +243,7 @@ List displays
243
243
A list display is a possibly empty series of expressions enclosed in square
244
244
brackets:
245
245
246
- .. productionlist ::
246
+ .. productionlist :: python-grammar
247
247
list_display: "[" [`starred_list ` | `comprehension `] "]"
248
248
249
249
A list display yields a new list object, the contents being specified by either
@@ -267,7 +267,7 @@ Set displays
267
267
A set display is denoted by curly braces and distinguishable from dictionary
268
268
displays by the lack of colons separating keys and values:
269
269
270
- .. productionlist ::
270
+ .. productionlist :: python-grammar
271
271
set_display: "{" (`starred_list ` | `comprehension `) "}"
272
272
273
273
A set display yields a new mutable set object, the contents being specified by
@@ -296,7 +296,7 @@ Dictionary displays
296
296
A dictionary display is a possibly empty series of key/datum pairs enclosed in
297
297
curly braces:
298
298
299
- .. productionlist ::
299
+ .. productionlist :: python-grammar
300
300
dict_display: "{" [`key_datum_list ` | `dict_comprehension `] "}"
301
301
key_datum_list: `key_datum ` ("," `key_datum `)* [","]
302
302
key_datum: `expression ` ":" `expression ` | "**" `or_expr `
@@ -355,7 +355,7 @@ Generator expressions
355
355
356
356
A generator expression is a compact generator notation in parentheses:
357
357
358
- .. productionlist ::
358
+ .. productionlist :: python-grammar
359
359
generator_expression: "(" `expression ` `comp_for ` ")"
360 360
361
361
A generator expression yields a new generator object. Its syntax is the same as
@@ -409,7 +409,7 @@ Yield expressions
409
409
pair: yield; expression
410
410
pair: generator; function
411
411
412
- .. productionlist ::
412
+ .. productionlist :: python-grammar
413
413
yield_atom: "(" `yield_expression ` ")"
414
414
yield_expression: "yield" [`expression_list ` | "from" `expression `]
415
415
@@ -746,7 +746,7 @@ Primaries
746
746
Primaries represent the most tightly bound operations of the language. Their
747
747
syntax is:
748
748
749
- .. productionlist ::
749
+ .. productionlist :: python-grammar
750
750
primary: `atom ` | `attributeref ` | `subscription ` | `slicing ` | `call `
751
751
752
752
@@ -761,7 +761,7 @@ Attribute references
761
761
762
762
An attribute reference is a primary followed by a period and a name:
763
763
764
- .. productionlist ::
764
+ .. productionlist :: python-grammar
765
765
attributeref: `primary ` "." `identifier `
766
766
767
767
.. index ::
@@ -799,7 +799,7 @@ Subscriptions
799
799
A subscription selects an item of a sequence (string, tuple or list) or mapping
800
800
(dictionary) object:
801
801
802
- .. productionlist ::
802
+ .. productionlist :: python-grammar
803
803
subscription: `primary ` "[" `expression_list ` "]"
804
804
805
805
The primary must evaluate to an object that supports subscription (lists or
@@ -855,7 +855,7 @@ A slicing selects a range of items in a sequence object (e.g., a string, tuple
855
855
or list). Slicings may be used as expressions or as targets in assignment or
856
856
:keyword: `del ` statements. The syntax for a slicing:
857
857
858
- .. productionlist ::
858
+ .. productionlist :: python-grammar
859
859
slicing: `primary ` "[" `slice_list ` "]"
860
860
slice_list: `slice_item ` ("," `slice_item `)* [","]
861
861
slice_item: `expression ` | `proper_slice `
@@ -905,7 +905,7 @@ Calls
905
905
A call calls a callable object (e.g., a :term: `function `) with a possibly empty
906
906
series of :term: `arguments <argument> `:
907
907
908
- .. productionlist ::
908
+ .. productionlist :: python-grammar
909
909
call: `primary ` "(" [`argument_list ` [","] | `comprehension `] ")"
910
910
argument_list: `positional_arguments ` ["," `starred_and_keywords `]
911
911
: ["," `keywords_arguments `]
@@ -1088,7 +1088,7 @@ Await expression
1088
1088
Suspend the execution of :term: `coroutine ` on an :term: `awaitable ` object.
1089
1089
Can only be used inside a :term: `coroutine function `.
1090
1090
1091
- .. productionlist ::
1091
+ .. productionlist :: python-grammar
1092
1092
await_expr: "await" `primary `
1093
1093
1094
1094
.. versionadded :: 3.5
@@ -1106,7 +1106,7 @@ The power operator
1106
1106
The power operator binds more tightly than unary operators on its left; it binds
1107
1107
less tightly than unary operators on its right. The syntax is:
1108
1108
1109
- .. productionlist ::
1109
+ .. productionlist :: python-grammar
1110
1110
power: (`await_expr ` | `primary `) ["**" `u_expr `]
1111
1111
1112
1112
Thus, in an unparenthesized sequence of power and unary operators, the operators
@@ -1139,7 +1139,7 @@ Unary arithmetic and bitwise operations
1139
1139
1140
1140
All unary arithmetic and bitwise operations have the same priority:
1141
1141
1142
- .. productionlist ::
1142
+ .. productionlist :: python-grammar
1143
1143
u_expr: `power ` | "-" `u_expr ` | "+" `u_expr ` | "~" `u_expr `
1144
1144
1145
1145
.. index ::
@@ -1183,7 +1183,7 @@ that some of these operations also apply to certain non-numeric types. Apart
1183
1183
from the power operator, there are only two levels, one for multiplicative
1184
1184
operators and one for additive operators:
1185
1185
1186
- .. productionlist ::
1186
+ .. productionlist :: python-grammar
1187
1187
m_expr: `u_expr ` | `m_expr ` "*" `u_expr ` | `m_expr ` "@" `m_expr ` |
1188
1188
: `m_expr ` "//" `u_expr ` | `m_expr ` "/" `u_expr ` |
1189
1189
: `m_expr ` "%" `u_expr `
@@ -1279,7 +1279,7 @@ Shifting operations
1279
1279
1280
1280
The shifting operations have lower priority than the arithmetic operations:
1281
1281
1282
- .. productionlist ::
1282
+ .. productionlist :: python-grammar
1283
1283
shift_expr: `a_expr ` | `shift_expr ` ("<<" | ">>") `a_expr `
1284
1284
1285
1285
These operators accept integers as arguments. They shift the first argument to
@@ -1300,7 +1300,7 @@ Binary bitwise operations
1300
1300
1301
1301
Each of the three bitwise operations has a different priority level:
1302
1302
1303
- .. productionlist ::
1303
+ .. productionlist :: python-grammar
1304
1304
and_expr: `shift_expr ` | `and_expr ` "&" `shift_expr `
1305
1305
xor_expr: `and_expr ` | `xor_expr ` "^" `and_expr `
1306
1306
or_expr: `xor_expr ` | `or_expr ` "|" `xor_expr`
@@ -1349,7 +1349,7 @@ lower than that of any arithmetic, shifting or bitwise operation. Also unlike
1349
1349
C, expressions like ``a < b < c `` have the interpretation that is conventional
1350
1350
in mathematics:
1351
1351
1352
- .. productionlist ::
1352
+ .. productionlist :: python-grammar
1353
1353
comparison: `or_expr ` (`comp_operator ` `or_expr `)*
1354
1354
comp_operator: "<" | ">" | "==" | ">=" | "<=" | "!="
1355
1355
: | "is" ["not"] | ["not"] "in"
@@ -1608,7 +1608,7 @@ Boolean operations
1608
1608
pair: Conditional; expression
1609
1609
pair: Boolean; operation
1610
1610
1611
- .. productionlist ::
1611
+ .. productionlist :: python-grammar
1612
1612
or_test: `and_test ` | `or_test ` "or" `and_test `
1613
1613
and_test: `not_test ` | `and_test ` "and" `not_test `
1614
1614
not_test: `comparison ` | "not" `not_test `
@@ -1647,7 +1647,7 @@ returns a boolean value regardless of the type of its argument
1647
1647
Assignment expressions
1648
1648
======================
1649
1649
1650
- .. productionlist ::
1650
+ .. productionlist :: python-grammar
1651
1651
assignment_expression: [`identifier ` ":="] `expression `
1652
1652
1653
1653
An assignment expression (sometimes also called a "named expression" or
@@ -1683,7 +1683,7 @@ Conditional expressions
1683
1683
single: if; conditional expression
1684
1684
single: else; conditional expression
1685
1685
1686
- .. productionlist ::
1686
+ .. productionlist :: python-grammar
1687
1687
conditional_expression: `or_test ` ["if" `or_test ` "else" `expression `]
1688
1688
expression: `conditional_expression ` | `lambda_expr `
1689
1689
expression_nocond: `or_test ` | `lambda_expr_nocond `
@@ -1710,7 +1710,7 @@ Lambdas
1710
1710
pair: anonymous; function
1711
1711
single: : (colon); lambda expression
1712
1712
1713
- .. productionlist ::
1713
+ .. productionlist :: python-grammar
1714
1714
lambda_expr: "lambda" [`parameter_list `] ":" `expression `
1715
1715
lambda_expr_nocond: "lambda" [`parameter_list `] ":" `expression_nocond `
1716
1716
@@ -1737,7 +1737,7 @@ Expression lists
1737
1737
pair: expression; list
1738
1738
single: , (comma); expression list
1739
1739
1740
- .. productionlist ::
1740
+ .. productionlist :: python-grammar
1741
1741
expression_list: `expression ` ("," `expression `)* [","]
1742
1742
starred_list: `starred_item ` ("," `starred_item `)* [","]
1743
1743
starred_expression: `expression ` | (`starred_item ` ",")* [`starred_item `]
0 commit comments