content_image/831618.jpg content_image/831619.jpg
## 6.8 Shifting operations 

The shifting operations have lower priority than the arithmetic operations: 

shift_expr ::= a_expr | shift_expr ("<<" | ">>") a_expr 

These operators accept integers as arguments. They shift the first argument to the left or right by the number of bits given by the second argument. 

A right shift by n bits is defined as floor division by pow(2,n) . A left shift by n bits is defined as multiplication with$_{pow(2,n)}$ . 

## 6.9 Binary bitwise operations 

Each of the three bitwise operations has a different priority level: 

<img src='content_image/831618.jpg'>

The$_{&}$operator yields the bitwise AND of its arguments, which must be integers. 

The$_{^}$ operator yields the bitwise XOR (exclusive OR) of its arguments, which must be integers. 

The$_{|}$ operator yields the bitwise (inclusive) OR of its arguments, which must be integers. 

## 6.10 Comparisons 

Unlike C, all comparison operations in Python have the same priority, which is lower than that of any arithmetic, shifting or bitwise operation. Also unlike C, expressions like$_{a < b < c}$ have the interpretation that is conventional in mathematics: 

<img src='content_image/831619.jpg'>

Comparisons yield boolean values:$_{True}$ or$_{False}$. 

Comparisons can be chained arbitrarily, e.g.,$_{x < y <= z}$ is equivalent to$_{x < y and y <= z}$ , except that$_{y}$ is evaluated only once (but in both cases$_{z}$ is not evaluated at all when$_{x < y}$is found to be false). 

Formally, if a , b , c , …, y , z are expressions and op1 , op2 , …, opN are comparison operators, then$_{a op1 b op2 c}$ ... y opN z is equivalent to$_{a op1 b and b op2 c and ... y opN z}$ , except that each expression is evaluated at most once. 

Note that$_{a op1 b op2 c}$ doesn’t imply any kind of comparison between a and c , so that, e.g.,$_{x < y > z}$ is perfectly legal (though perhaps not pretty). 

