> ## 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 Keyword-Only Parameter

Keyword-only parameters are function arguments that can only be supplied using keyword syntax (`parameter_name=value`) during invocation. They cannot be bound to positional arguments. If a caller attempts to pass a keyword-only parameter positionally, the Python interpreter raises a `TypeError`.

In a function signature, keyword-only parameters are defined by placing them after a var-positional parameter (typically `*args`) or after a bare asterisk (`*`).

## Syntax Visualization

**1. Using a Bare Asterisk (`*`)**
The bare asterisk consumes no arguments but dictates that all subsequent parameters in the signature are keyword-only.

```python theme={"dark"}
def configure_server(host, port, *, secure, timeout=30):
    # 'host' and 'port' can be positional or keyword.
    # 'secure' and 'timeout' are strictly keyword-only.
    pass


# Valid Invocation
configure_server("127.0.0.1", 8080, secure=True)
configure_server("127.0.0.1", 8080, secure=True, timeout=60)


# Invalid Invocation: Raises TypeError (takes 2 positional arguments but 3 were given)
configure_server("127.0.0.1", 8080, True) 
```

**2. Following a Var-Positional Parameter (`*args`)**
When a function accepts an arbitrary number of positional arguments via `*args`, any standard parameters defined after it automatically become keyword-only.

```python theme={"dark"}
def concatenate_strings(*strings, delimiter=","):
    # 'strings' captures all positional arguments as a tuple.
    # 'delimiter' is keyword-only.
    return delimiter.join(strings)


# Valid Invocation
concatenate_strings("apple", "banana", "cherry", delimiter="|")


# Syntactically valid, but "->" is absorbed into the *strings tuple, 

# leaving 'delimiter' at its default value.
concatenate_strings("apple", "banana", "cherry", "->") 
```

## Parameter Ordering Rules

When constructing a function signature, Python enforces a strict parameter resolution order. Keyword-only parameters must be placed according to the following hierarchy:

1. Positional-only parameters (preceding `/`)
2. Standard parameters (positional or keyword)
3. Var-positional parameter (`*args`) OR bare asterisk (`*`)
4. **Keyword-only parameters**
5. Var-keyword parameter (`**kwargs`)

```python theme={"dark"}

# Comprehensive Signature Example
def complex_function(pos_only, /, standard, *args, kw_only1, kw_only2="default", **kwargs):
    pass
```

## Required vs. Optional

Keyword-only parameters can be required or optional.

* If a keyword-only parameter is defined **without** a default value (e.g., `secure` in the first example), it is a *required* keyword-only parameter. Omitting it during invocation raises a `TypeError: missing 1 required keyword-only argument`.
* If it is defined **with** a default value (e.g., `timeout=30`), it is optional.

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