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 & right

Parameters & Attributes

NameTypeDescription
leftint, set or supporting objectFirst operand; its type participates in operation selection.
rightint, set or supporting objectSecond 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}))
Python Reference