> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Bitwise OR Assignment

The `|=` operator is the augmented assignment operator used for bitwise OR, set union, and dictionary merging. It evaluates the expression on its right-hand side, applies the underlying OR logic between the left-hand variable and the evaluated right-hand result, and binds the resulting value back to the left-hand variable.

Under the hood, `a |= b` invokes the `__ior__(self, other)` (in-place OR) magic method on the left operand. If the left operand is a mutable type that implements `__ior__`, the object is modified in place. If `__ior__` is not implemented (as with immutable types), Python falls back to the standard `__or__(self, other)` method and reassigns the result to the left variable (`a = a | b`).

```python theme={"dark"}
variable |= expression
```

The mechanical behavior of `|=` depends strictly on the data type of the left-hand operand:

## Integers (Bitwise OR)

When applied to integers, `|=` performs a bitwise OR operation on the binary representations of the operands. For each bit position, if the bit is `1` in either the left or right operand, the resulting bit is set to `1`. Because integers are immutable, this operation creates a new integer object and rebinds it to the variable.

```python theme={"dark"}
a = 10     # Binary: 1010
a |= 6     # Binary: 0110

# a is now 14 (Binary: 1110)
```

## Sets (In-Place Union)

When the left operand is a `set`, `|=` performs an in-place union. It mutates the original set object by adding all unique elements from the right operand. Unlike the `set.update()` method (which accepts any iterable), the `|=` operator strictly requires the right-hand operand to also be a set. Attempting to use a non-set iterable (like a list or tuple) will raise a `TypeError`.

```python theme={"dark"}
s = {1, 2}
s |= {2, 3, 4}  # Right operand must strictly be a set

# s is mutated to {1, 2, 3, 4}
```

## Dictionaries (In-Place Merge)

Introduced in Python 3.9 (PEP 584), when the left operand is a `dict`, `|=` performs an in-place dictionary merge. It mutates the left dictionary by inserting key-value pairs from the right operand. In the event of key collisions, the value from the right-hand operand overwrites the value in the left-hand operand.

Unlike the standard `|` operator (which strictly requires both operands to be mappings), the `|=` operator for dictionaries accepts either a mapping **or any iterable of key-value pairs** (such as a list of tuples) on the right-hand side, mirroring the behavior of the `dict.update()` method.

```python theme={"dark"}
d = {'a': 1, 'b': 2}
d |= [('b', 99), ('c', 3)]  # Right operand can be an iterable of pairs

# d is mutated to {'a': 1, 'b': 99, 'c': 3}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Python Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
