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

The `**` operator in Python serves two distinct syntactic roles depending on its lexical context: as a binary arithmetic exponentiation operator for numeric types, and as a mapping unpacking or packing token for dictionary-like objects.

## Arithmetic Exponentiation

When used as a binary operator between two expressions, `**` performs exponentiation, raising the left operand to the power of the right operand.

**Underlying Mechanics:**
The operator delegates to the `__pow__(self, other)` magic method of the left operand. If the left operand does not support the operation or returns `NotImplemented`, Python falls back to the right operand's `__rpow__(self, other)` method.

**Associativity and Precedence:**
Unlike most Python operators, `**` is **right-associative**. The expression `x ** y ** z` is evaluated as `x ** (y ** z)`.

It also binds more tightly than unary arithmetic operators on its left, but less tightly than unary operators on its right.

```python theme={"dark"}

# Basic syntax
result = 2 ** 3  # Evaluates to 8


# Right-associativity
chain = 2 ** 3 ** 2  # Evaluates to 512 (2 ** 9), not 64 (8 ** 2)


# Precedence with unary operators
neg_a = -3 ** 2   # Evaluates to -9. Parsed as -(3 ** 2)
neg_b = (-3) ** 2 # Evaluates to 9. Parsed as (-3) ** 2
```

## Mapping Unpacking and Packing

When prefixed to an expression within a dictionary literal or a function call, `**` acts as an unpacking operator. It is not a standalone operator that evaluates to a value; rather, it is a syntactic construct resolved by the Python parser to expand a mapping object into discrete key-value pairs.

**Underlying Mechanics:**
Because Python utilizes duck typing, the operand following `**` does not need to formally inherit from or register with the `collections.abc.Mapping` abstract base class. It only needs to implement the mapping protocol—specifically the `keys()` and `__getitem__()` methods. Python internally iterates over the mapping's keys and retrieves the corresponding values to populate the target structure.

**Contextual Syntax:**

* **Dictionary Displays:** Expands the key-value pairs into a new dictionary literal. If duplicate keys exist, the values from the rightmost unpacked mapping overwrite previous values.
* **Function Invocations:** Expands the mapping into discrete keyword arguments. The keys must be strings. These string keys must match the function's explicitly defined parameter names, unless the function signature includes a `**kwargs` catch-all parameter, in which case any valid string key is accepted. This unpacking is evaluated dynamically at runtime; the compiler emits a bytecode instruction (such as `CALL_FUNCTION_EX`) to handle the expansion during execution.
* **Function Signatures:** When used in a function definition (`def func(**kwargs):`), it acts as a packing parameter, capturing all unbound keyword arguments into a single dictionary bound to the specified identifier.

```python theme={"dark"}

# Dictionary display unpacking
map1 = {'a': 1, 'b': 2}
map2 = {'b': 3, 'c': 4}
combined = {**map1, **map2}  # Evaluates to {'a': 1, 'b': 3, 'c': 4}


# Function invocation unpacking
def target_function(a, b):
    pass

args = {'a': 10, 'b': 20}
target_function(**args)  # Evaluated dynamically at runtime via CALL_FUNCTION_EX


# Function signature packing
def capture_kwargs(**kwargs):
    # kwargs is bound to a dictionary of passed keyword arguments
    pass
```

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