> ## 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 Value Pattern

A value pattern in Python's structural pattern matching evaluates whether a subject is equal to the value of a specific named attribute. Defined strictly by Python's formal grammar (PEP 634), a value pattern must be expressed as a **dotted name** (e.g., `Constants.TARGET` or `HttpStatus.OK`). This syntactic requirement distinguishes value patterns from **literal patterns** (which match raw literals like `200` or `None`) and **capture patterns** (which bind the subject to a bare identifier).

## Syntax and Mechanics

A value pattern requires at least one dot (`.`) in the identifier name. This typically involves referencing an enumeration, a class attribute, or a module-level constant.

```python theme={"dark"}
from enum import IntEnum
import math

class HttpStatus(IntEnum):
    OK = 200
    NOT_FOUND = 404

class Config:
    MAX_RETRIES = 3

subject = 200

match subject:
    case HttpStatus.OK:        # Value pattern (resolves to IntEnum member, 200 == 200)
        pass
    case Config.MAX_RETRIES:   # Value pattern (resolves to class attribute)
        pass
    case math.pi:              # Value pattern (resolves to module attribute)
        pass
```

## Evaluation Semantics

When the Python interpreter evaluates a value pattern, it performs the following steps:

1. It resolves the dotted name to its underlying object.
2. It compares the resolved object to the subject using the equality operator (`==`).
3. The pattern succeeds if `subject == resolved_value` evaluates to `True`.

Because the comparison relies on `==`, standard type equality rules apply. In the example above, `HttpStatus` must inherit from `IntEnum` for the integer `200` to evaluate as equal to the enum member `HttpStatus.OK`. If a standard `Enum` were used, `200 == HttpStatus.OK` would evaluate to `False`, and the pattern would fail to match.

## The Dotted Name Requirement

A critical technical distinction in Python's pattern matching grammar is how it differentiates between a **value pattern** (which compares) and a **capture pattern** (which assigns).

To match against a pre-defined constant or variable, the pattern **must** be a dotted name. If a bare identifier is used, Python's compiler interprets it as a capture pattern. A capture pattern unconditionally binds the subject to that variable name and succeeds. Because `match`/`case` blocks do not create a new scope, using a bare identifier overwrites (rebinds) any existing variable with that name in the current scope.

```python theme={"dark"}
class Constants:
    TARGET = 42

TARGET = 42
subject = 99

match subject:
    # VALUE PATTERN: Requires a dotted name.
    # Compares subject == Constants.TARGET (evaluates to False).
    case Constants.TARGET:
        print("Matched the constant value.")
        
    # CAPTURE PATTERN: Uses a bare identifier.
    # This does NOT compare subject == 42. It unconditionally succeeds 
    # and rebinds the local variable 'TARGET' to 99.
    case TARGET:
        print(f"Captured subject into variable TARGET: {TARGET}")
```

## Value Patterns vs. Literal Patterns

While both pattern types are used to match specific values, Python's grammar classifies them as distinct entities based on their syntax:

* **Value Pattern:** Requires attribute access via a dot (`.`). The value is resolved dynamically at runtime (e.g., `Color.RED`, `settings.DEFAULT_TIMEOUT`).
* **Literal Pattern:** Uses hardcoded literal values directly in the syntax. This includes numbers (`42`), strings (`"success"`), and singletons (`None`, `True`, `False`). Literal patterns matching singletons use object identity (`is`) rather than equality (`==`).

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