&= Bitwise AND assignment
Last updated: 2026-09-22
&= Bitwise AND assignment
&= computes a bitwise AND of the left variable with the right value, equivalent to x = x & y.
| Category | Operators |
|---|---|
| Kind | Operator |
📝 Syntax
x &= y
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
2
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat do x &= y do to integers and sets respectively?
AFor integers it does bitwise AND and rebinds: with `x = 6; x &= 3`, `x == 2`. For sets it is an in-place intersection: `s &= {1}` is equivalent to `s.intersection_update({1})`.
QIs &= completely equivalent to x = x & y?
AFor immutable types (int) it is fully equivalent; for sets, `&=` uses `__iand__` to operate in place, slightly more efficient and without replacing the object (same `id`).
QMust x in x &= y be an integer?
ANo. Sets work too: with `s = {1, 2}; s &= {2, 3}`, `s == {2}`.