@@ -1351,67 +1351,62 @@ Formally, imaginary literals are described by the following lexical definition:
13511351 imagnumber: (`floatnumber ` | `digitpart `) ("j" | "J")
13521352
13531353
1354- .. _operators :
1355-
1356- Operators
1357- =========
1358-
1359- .. index :: single: operators
1360-
1361- The following tokens are operators:
1362-
1363- .. code-block :: none
1364-
1365-
1366- + - * ** / // % @
1367- << >> & | ^ ~ :=
1368- < > <= >= == !=
1369-
1370-
13711354.. _delimiters :
1372-
1373- Delimiters
1374- ==========
1375-
1376- .. index :: single: delimiters
1377-
1378- The following tokens serve as delimiters in the grammar:
1379-
1380- .. code-block :: none
1381-
1382- ( ) [ ] { }
1383- , : ! . ; @ =
1384-
1385- The period can also occur in floating-point and imaginary literals.
1386-
1355+ .. _operators :
13871356.. _lexical-ellipsis :
13881357
1389- A sequence of three periods has a special meaning as an
1390- :py:data: `Ellipsis ` literal:
1391-
1392- .. code-block :: none
1393-
1394- ...
1395-
1396- The following *augmented assignment operators * serve
1397- lexically as delimiters, but also perform an operation:
1358+ Operators and delimiters
1359+ ========================
13981360
1399- .. code-block :: none
1400-
1401- -> += -= *= /= //= %=
1402- @= &= |= ^= >>= <<= **=
1403-
1404- The following printing ASCII characters have special meaning as part of other
1405- tokens or are otherwise significant to the lexical analyzer:
1406-
1407- .. code-block :: none
1408-
1409- ' " # \
1361+ .. index ::
1362+ single: operators
1363+ single: delimiters
14101364
1411- The following printing ASCII characters are not used in Python. Their
1412- occurrence outside string literals and comments is an unconditional error:
1365+ The following grammar defines :dfn: `operator ` and :dfn: `delimiter ` tokens,
1366+ that is, the generic :data: `~token.OP ` token type.
1367+ A :ref: `list of these tokens and their names <token_operators_delimiters >`
1368+ is also available in the :mod: `!token ` module documentation.
14131369
1414- .. code-block :: none
1370+ .. grammar-snippet ::
1371+ :group: python-grammar
14151372
1416- $ ? `
1373+ OP:
1374+ | assignment_operator
1375+ | bitwise_operator
1376+ | comparison_operator
1377+ | enclosing_delimiter
1378+ | other_delimiter
1379+ | arithmetic_operator
1380+ | "..."
1381+ | other_op
1382+
1383+ assignment_operator: "+=" | "-=" | "*=" | "**=" | "/=" | "//=" | "%=" |
1384+ "&=" | "|=" | "^=" | "<<=" | ">>=" | "@=" | ":="
1385+ bitwise_operator: "&" | "|" | "^" | "~" | "<<" | ">>"
1386+ comparison_operator: "<=" | ">=" | "<" | ">" | "==" | "!="
1387+ enclosing_delimiter: "(" | ")" | "[" | "]" | "{" | "}"
1388+ other_delimiter: "," | ":" | "!" | ";" | "=" | "->"
1389+ arithmetic_operator: "+" | "-" | "* *" | "*" | "//" | "/" | "%"
1390+ other_op: "." | "@"
1391+
1392+ .. note ::
1393+
1394+ Generally, *operators * are used to combine :ref: `expressions <expressions >`,
1395+ while *delimiters * serve other purposes.
1396+ However, there is no clear, formal distinction between the two categories.
1397+
1398+ Some tokens can serve as either operators or delimiters, depending on usage.
1399+ For example, ``* `` is both the multiplication operator and a delimiter used
1400+ for sequence unpacking, and ``@ `` is both the matrix multiplication and
1401+ a delimiter that introduces decorators.
1402+
1403+ For some tokens, the distinction is unclear.
1404+ For example, some people consider ``. ``, ``( ``, and ``) `` to be delimiters, while others
1405+ see the :py:func: `getattr ` operator and the function call operator(s).
1406+
1407+ Some of Python's operators, like ``and ``, ``or ``, and ``not in ``, use
1408+ :ref: `keyword <keywords >` tokens rather than "symbols" (operator tokens).
1409+
1410+ A sequence of three consecutive periods (``... ``) has a special
1411+ meaning as an :py:data: `Ellipsis ` literal.
14171412
0 commit comments