mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
added table of precedences
This commit is contained in:
parent
55dd113bc8
commit
4dd6b84e5f
2 changed files with 102 additions and 0 deletions
|
|
@ -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}
|
||||
|
|
|
|||
51
Doc/ref5.tex
51
Doc/ref5.tex
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue