Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4dd6b84e
Commit
4dd6b84e
authored
Mar 17, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added table of precedences
parent
55dd113b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
0 deletions
+102
-0
Doc/ref/ref5.tex
Doc/ref/ref5.tex
+51
-0
Doc/ref5.tex
Doc/ref5.tex
+51
-0
No files found.
Doc/ref/ref5.tex
View file @
4dd6b84e
...
...
@@ -705,3 +705,54 @@ tuple, but rather yields the value of that expression (condition).
(To create an empty tuple, use an empty pair of parentheses:
\verb
@
()
@
.)
\section
{
Summary
}
The following table summarizes the operator precedences in Python,
from lowest precedence (least binding) to highest precedence (most
binding). Operators in the same box have the same precedence. Unless
the syntax is explicitly given, operators are binary. Operators in
the same box group left to right (except for comparisons, which
chain from left to right --- see above).
\begin{center}
\begin{tabular}
{
|c|c|
}
\hline
\code
{
or
}
&
Boolean OR
\\
\hline
\code
{
and
}
&
Boolean AND
\\
\hline
\code
{
not
}
\var
{
x
}
&
Boolean NOT
\\
\hline
\code
{
in
}
,
\code
{
not
}
\code
{
in
}
&
Membership tests
\\
\code
{
is
}
,
\code
{
is
}
\code
{
not
}
&
Identity tests
\\
\code
{
<
}
,
\code
{
<=
}
,
\code
{
>
}
,
\code
{
>=
}
,
\code
{
<>
}
,
\code
{
!=
}
,
\code
{
=
}
&
Comparisons
\\
\hline
\code
{
|
}
&
Bitwise OR
\\
\hline
\code
{
\^
}
&
Bitwise XOR
\\
\hline
\code
{
\&
}
&
Bitwise AND
\\
\hline
\code
{
<<
}
,
\code
{
>>
}
&
Shifts
\\
\hline
\code
{
+
}
,
\code
{
-
}
&
Addition and subtraction
\\
\hline
\code
{
*
}
,
\code
{
/
}
,
\code
{
\%
}
&
Multiplication, division, remainder
\\
\hline
\code
{
+
\var
{
x
}}
,
\code
{
-
\var
{
x
}}
&
Positive, negative
\\
\code
{
\~\var
{
x
}}
&
Bitwise not
\\
\hline
\code
{
\var
{
x
}
.
\var
{
attribute
}}
&
Attribute reference
\\
\code
{
\var
{
x
}
[
\var
{
index
}
]
}
&
Subscription
\\
\code
{
\var
{
x
}
[
\var
{
index
}
:
\var
{
index
}
]
}
&
Slicing
\\
\code
{
\var
{
f
}
(
\var
{
arguments
}
...)
}
&
Function call
\\
\hline
\code
{
(
\var
{
expressions
}
\ldots
)
}
&
Binding or tuple display
\\
\code
{
[
\var
{
expressions
}
\ldots
]
}
&
List display
\\
\code
{
\{\var
{
key
}
:
\var
{
datum
}
\ldots\}
}
&
Dictionary display
\\
\code
{
`
\var
{
expression
}
\ldots
`
}
&
String conversion
\\
\hline
\end{tabular}
\end{center}
Doc/ref5.tex
View file @
4dd6b84e
...
...
@@ -705,3 +705,54 @@ tuple, but rather yields the value of that expression (condition).
(To create an empty tuple, use an empty pair of parentheses:
\verb
@
()
@
.)
\section
{
Summary
}
The following table summarizes the operator precedences in Python,
from lowest precedence (least binding) to highest precedence (most
binding). Operators in the same box have the same precedence. Unless
the syntax is explicitly given, operators are binary. Operators in
the same box group left to right (except for comparisons, which
chain from left to right --- see above).
\begin{center}
\begin{tabular}
{
|c|c|
}
\hline
\code
{
or
}
&
Boolean OR
\\
\hline
\code
{
and
}
&
Boolean AND
\\
\hline
\code
{
not
}
\var
{
x
}
&
Boolean NOT
\\
\hline
\code
{
in
}
,
\code
{
not
}
\code
{
in
}
&
Membership tests
\\
\code
{
is
}
,
\code
{
is
}
\code
{
not
}
&
Identity tests
\\
\code
{
<
}
,
\code
{
<=
}
,
\code
{
>
}
,
\code
{
>=
}
,
\code
{
<>
}
,
\code
{
!=
}
,
\code
{
=
}
&
Comparisons
\\
\hline
\code
{
|
}
&
Bitwise OR
\\
\hline
\code
{
\^
}
&
Bitwise XOR
\\
\hline
\code
{
\&
}
&
Bitwise AND
\\
\hline
\code
{
<<
}
,
\code
{
>>
}
&
Shifts
\\
\hline
\code
{
+
}
,
\code
{
-
}
&
Addition and subtraction
\\
\hline
\code
{
*
}
,
\code
{
/
}
,
\code
{
\%
}
&
Multiplication, division, remainder
\\
\hline
\code
{
+
\var
{
x
}}
,
\code
{
-
\var
{
x
}}
&
Positive, negative
\\
\code
{
\~\var
{
x
}}
&
Bitwise not
\\
\hline
\code
{
\var
{
x
}
.
\var
{
attribute
}}
&
Attribute reference
\\
\code
{
\var
{
x
}
[
\var
{
index
}
]
}
&
Subscription
\\
\code
{
\var
{
x
}
[
\var
{
index
}
:
\var
{
index
}
]
}
&
Slicing
\\
\code
{
\var
{
f
}
(
\var
{
arguments
}
...)
}
&
Function call
\\
\hline
\code
{
(
\var
{
expressions
}
\ldots
)
}
&
Binding or tuple display
\\
\code
{
[
\var
{
expressions
}
\ldots
]
}
&
List display
\\
\code
{
\{\var
{
key
}
:
\var
{
datum
}
\ldots\}
}
&
Dictionary display
\\
\code
{
`
\var
{
expression
}
\ldots
`
}
&
String conversion
\\
\hline
\end{tabular}
\end{center}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment