> ## 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 Left Shift Assignment

The `<<=` operator is the bitwise left shift assignment operator in Python. It shifts the binary representation of the left operand to the left by the number of bits specified by the right operand, and assigns the resulting value back to the left operand.

```python theme={"dark"}
x <<= y
```

This operation is functionally equivalent to:

```python theme={"dark"}
x = x << y
```

## Mechanics

When the `<<=` operator is applied, the following technical behaviors occur:

1. **Bit Manipulation:** The binary bits of the left operand are shifted to the left. For every position shifted, a `0` is appended to the least significant bit (right side).
2. **Arbitrary Precision:** Unlike languages with fixed-width integers (e.g., C or Java), Python's `int` type has arbitrary precision. Therefore, shifting left will never cause an arithmetic overflow or truncate the most significant bits. The bit-length of the integer simply grows to accommodate the new magnitude.
3. **Mathematical Equivalence:** Shifting an integer left by `y` positions is mathematically identical to multiplying the integer by $2^y$.
4. **Operand Constraints:** The right operand (`y`) must be a non-negative integer. If `y` is negative, Python raises a `ValueError: negative shift count`. Both operands must be integers; using floats or other types raises a `TypeError`.

## Object Model Implementation

Under the hood, the `<<=` operator invokes the in-place left shift magic method (dunder method).

When `x <<= y` is executed, Python attempts to call:

```python theme={"dark"}
x.__ilshift__(y)
```

If the left operand's class does not implement `__ilshift__`, Python falls back to the standard left shift method and reassigns the result:

```python theme={"dark"}
x = x.__lshift__(y)
```

## Execution Examples

```python theme={"dark"}

# Base integer assignment
x = 5        # Binary: 101
x <<= 3      # Shift left by 3 bits. Binary becomes: 101000
print(x)     # Output: 40 (Equivalent to 5 * 2^3)


# Negative integer assignment
y = -7       
y <<= 2      
print(y)     # Output: -28 (Equivalent to -7 * 2^2)


# Zero assignment
z = 0        # Binary: 0
z <<= 5      # Shift left by 5 bits. Binary remains: 0
print(z)     # Output: 0
```

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