Operators
& — Bitwise AND and set intersection
For integers, keeps bit positions where both operands have a one. For two bool operands returns a bool; mixing bool and int yields an int for built-in operands. Set operands compute intersection. This operator evaluates both operands and is not the short-circuit and keyword. __and__ and __rand__ implement custom behavior. Shifts bind more tightly than &, which in turn binds more tightly than ^ and |.
Formal Syntax & Structure
python syntaxpython
left & rightParameters & Attributes
| Name | Type | Description |
|---|---|---|
| left | int, set or supporting object | First operand; its type participates in operation selection. |
| right | int, set or supporting object | Second operand; supported values depend on the operand types. |
Return Value
object
Result selected by the operand types and their operation implementations.
Working Example
Example Snippetpython
print(0b1101 & 0b1011)print(True & False)print(sorted({1, 2} & {2, 3}))