|
| 1 | +<?xml version="1.0"?> |
1 | 2 | <section xml:id="appendices_operator-precedence-table"> |
2 | | - <title>Operator precedence table</title> |
3 | | - |
4 | | - |
5 | | - <p xml:id="appendices_index-0">The following table summarizes the operator precedence of Python operators <em>in this book</em>, from |
| 3 | + <title>Operator precedence table</title> |
| 4 | + <p xml:id="appendices_index-0">The following table summarizes the operator precedence of Python operators <em>in this book</em>, from |
6 | 5 | highest precedence (most binding) to lowest |
7 | 6 | precedence (least binding). Operators in |
8 | 7 | the same box have the same precedence. Unless syntax is explicitly given, |
9 | 8 | operators are binary. Operators in the same box group left to right (except for |
10 | 9 | exponentiation, which groups from right to left). |
11 | 10 | This is many of the entries from the complete Python table at |
12 | 11 | <url href="https://docs.python.org/3/reference/expressions.html#operator-precedence" visual="https://docs.python.org/3/reference/expressions.html#operator-precedence">https://docs.python.org/3/reference/expressions.html#operator-precedence</url>.</p> |
13 | | - <p>In the row for comparisons, membership tests, and identity tests, all have the same |
| 12 | + <p>In the row for comparisons, membership tests, and identity tests, all have the same |
14 | 13 | precedence and have a left-to-right chaining feature; for example <c>3 < x <= y != z</c>.</p> |
15 | | - <table><tabular> |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - <row header="yes"> |
21 | | - <cell> |
| 14 | + <table> |
| 15 | + <tabular> |
| 16 | + <row header="yes"> |
| 17 | + <cell> |
22 | 18 | Operator |
23 | 19 | </cell> |
24 | | - <cell> |
| 20 | + <cell> |
25 | 21 | Description |
26 | 22 | </cell> |
27 | | - </row> |
28 | | - |
29 | | - |
30 | | - <row> |
31 | | - <cell> |
32 | | - <c>(expressions...)</c>, |
| 23 | + </row> |
| 24 | + <row> |
| 25 | + <cell><c>(expressions...)</c>, |
33 | 26 | <c>[expressions...]</c>, |
34 | 27 | <c>{key: value...}</c>, |
35 | | - <c>{expressions...}</c> |
36 | | - </cell> |
37 | | - <cell> |
| 28 | + <c>{expressions...}</c></cell> |
| 29 | + <cell> |
38 | 30 | Binding or tuple display, |
39 | 31 | list display, |
40 | 32 | dictionary display, |
41 | 33 | set display |
42 | 34 | </cell> |
43 | | - </row> |
44 | | - <row> |
45 | | - <cell> |
46 | | - <c>x[index]</c>, <c>x[index:index]</c>, |
47 | | - <c>x(arguments...)</c>, <c>x.attribute</c> |
48 | | - </cell> |
49 | | - <cell> |
| 35 | + </row> |
| 36 | + <row> |
| 37 | + <cell><c>x[index]</c>, <c>x[index:index]</c>, |
| 38 | + <c>x(arguments...)</c>, <c>x.attribute</c></cell> |
| 39 | + <cell> |
50 | 40 | Subscription, slicing, |
51 | 41 | call, attribute reference |
52 | 42 | </cell> |
53 | | - </row> |
54 | | - <row> |
55 | | - <cell> |
56 | | - <c>**</c> |
57 | | - </cell> |
58 | | - <cell> |
| 43 | + </row> |
| 44 | + <row> |
| 45 | + <cell> |
| 46 | + <c>**</c> |
| 47 | + </cell> |
| 48 | + <cell> |
59 | 49 | Exponentiation |
60 | 50 | (groups right to left) |
61 | 51 | </cell> |
62 | | - </row> |
63 | | - <row> |
64 | | - <cell> |
65 | | - <c>-x</c> |
66 | | - </cell> |
67 | | - <cell> |
| 52 | + </row> |
| 53 | + <row> |
| 54 | + <cell> |
| 55 | + <c>-x</c> |
| 56 | + </cell> |
| 57 | + <cell> |
68 | 58 | Negation |
69 | 59 | </cell> |
70 | | - </row> |
71 | | - <row> |
72 | | - <cell> |
73 | | - <c>*</c>, <c>/</c>, <c>//</c>, <c>%</c> |
74 | | - </cell> |
75 | | - <cell> |
| 60 | + </row> |
| 61 | + <row> |
| 62 | + <cell><c>*</c>, <c>/</c>, <c>//</c>, <c>%</c></cell> |
| 63 | + <cell> |
76 | 64 | Multiplication, |
77 | 65 | real and integer division, |
78 | 66 | remainder |
79 | 67 | </cell> |
80 | | - </row> |
81 | | - <row> |
82 | | - <cell> |
83 | | - <c>+</c>, <c>-</c> |
84 | | - </cell> |
85 | | - <cell> |
| 68 | + </row> |
| 69 | + <row> |
| 70 | + <cell><c>+</c>, <c>-</c></cell> |
| 71 | + <cell> |
86 | 72 | Addition and subtraction |
87 | 73 | </cell> |
88 | | - </row> |
89 | | - <row> |
90 | | - <cell> |
91 | | - <c>in</c>, <c>not in</c>, <c>is</c>, <c>is not</c>, |
92 | | - <c><</c>, <c><=</c>, <c>></c>, <c>>=</c>, <c>!=</c>, <c>==</c> |
93 | | - </cell> |
94 | | - <cell> |
| 74 | + </row> |
| 75 | + <row> |
| 76 | + <cell><c>in</c>, <c>not in</c>, <c>is</c>, <c>is not</c>, |
| 77 | + <c><</c>, <c><=</c>, <c>></c>, <c>>=</c>, <c>!=</c>, <c>==</c></cell> |
| 78 | + <cell> |
95 | 79 | Comparisons, including membership |
96 | 80 | tests and identity tests |
97 | 81 | </cell> |
98 | | - </row> |
99 | | - <row> |
100 | | - <cell> |
101 | | - <c>not x</c> |
102 | | - </cell> |
103 | | - <cell> |
| 82 | + </row> |
| 83 | + <row> |
| 84 | + <cell> |
| 85 | + <c>not x</c> |
| 86 | + </cell> |
| 87 | + <cell> |
104 | 88 | Boolean NOT |
105 | 89 | </cell> |
106 | | - </row> |
107 | | - <row> |
108 | | - <cell> |
109 | | - <c>and</c> |
110 | | - </cell> |
111 | | - <cell> |
| 90 | + </row> |
| 91 | + <row> |
| 92 | + <cell> |
| 93 | + <c>and</c> |
| 94 | + </cell> |
| 95 | + <cell> |
112 | 96 | Boolean AND |
113 | 97 | </cell> |
114 | | - </row> |
115 | | - <row> |
116 | | - <cell> |
117 | | - <c>or</c> |
118 | | - </cell> |
119 | | - <cell> |
| 98 | + </row> |
| 99 | + <row> |
| 100 | + <cell> |
| 101 | + <c>or</c> |
| 102 | + </cell> |
| 103 | + <cell> |
120 | 104 | Boolean OR |
121 | 105 | </cell> |
122 | | - </row> |
123 | | - |
124 | | - |
125 | | - </tabular></table> |
126 | | - </section> |
127 | | - |
| 106 | + </row> |
| 107 | + </tabular> |
| 108 | + </table> |
| 109 | +</section> |
0 commit comments