Dev Helpers

Python / Functional patterns

Define positional-only and keyword-only arguments

Dev Helpers · September 27, 2025

A function signature can distinguish the item being processed from optional policies. A keyword-only flag makes call sites easier to read.

Worked example

def price(amount, /, *, tax=0):
    return amount + tax
print(price(12, tax=2))

Result

14

Implementation notes

Keyword-only options help when several arguments share the same type. Swapping two boolean flags can otherwise remain valid Python while reversing behaviour.

Try it yourself

Move a keyword-only value into the positional argument list.

Open the Python example →

Editorial date September 27, 2025 · Published December 6, 2026

Related articles

Run an async function

An async function call creates a coroutine. A top-level runner supplies the event loop that executes it.

Transpose a matrix

Transposing rows into columns assumes a decision about uneven rows. Ordinary zip stops at the shortest input.

Unpack with a remainder

Starred unpacking separates a fixed header from a variable-length tail. It still requires enough elements for the fixed positions.