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

The `is` operator in Python is an object identity operator. It evaluates whether two variables reference the exact same object in memory, rather than checking if their underlying values are equivalent.

When the `is` operator is invoked, Python compares the memory addresses of the operands. Under the hood, the expression `a is b` is functionally equivalent to evaluating `id(a) == id(b)`, where the CPython `id()` function returns the integer representation of an object's memory address.

```python theme={"dark"}
expression_1 is expression_2
expression_1 is not expression_2
```

## Identity vs. Equality

The distinction between `is` (identity) and `==` (equality) is a fundamental mechanic in Python's memory management. Two distinct objects can hold identical data, satisfying the `==` operator, while failing the `is` operator because they occupy different memory locations.

```python theme={"dark"}

# Two distinct list objects allocated in memory with identical values
list_a = [1, 2, 3]
list_b = [1, 2, 3]


# Equality (==) evaluates to True because the data matches
print(list_a == list_b)  # Output: True


# Identity (is) evaluates to False because they are different objects in memory
print(list_a is list_b)  # Output: False


# Assigning list_a to list_c copies the memory reference, not the object itself
list_c = list_a
print(list_a is list_c)  # Output: True
```

## CPython Interning and Singletons

The evaluation of the `is` operator is heavily influenced by CPython's memory optimization techniques, specifically object interning. CPython pre-allocates and caches certain immutable objects as singletons to save memory. When variables are assigned these specific values, Python points them to the same cached memory address.

1. **Small Integers:** CPython caches integers in the range of `-5` to `256`.
2. **Strings:** String literals containing only ASCII letters, digits, or underscores are typically interned.
3. **Built-in Constants:** `None`, `True`, and `False` are strict singletons.

```python theme={"dark"}

# 100 falls within the cached integer range (-5 to 256)
x = 100
y = 100
print(x is y)  # Output: True


# 1000 falls outside the cached range, resulting in distinct object allocations
a = 1000
b = 1000
print(a is b)  # Output: False (Note: Behavior may vary depending on compiler optimizations in scripts vs REPL)
```

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