Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
Python interview question
Functions & functional toolsSeniorOccasionalTheory

What do the `/` and `*` markers do in a function signature like `def f(a, b, /, c, *, d):`?

Answer

Parameters before a bare `/` are positional-only: callers must pass them by position and can never use their parameter name as a keyword. Parameters after a bare `*` are keyword-only: callers must pass them by name and can never rely on their position. In `def f(a, b, /, c, *, d):`, `a` and `b` are positional-only, `c` can be passed either way, and `d` must be passed as `d=value`. This lets an API designer lock down a stable calling convention, hide internal parameter names from the public call syntax, and avoid accidental positional misordering for less obvious arguments.

Strong answer includes

  • parameters before / are positional-only
  • parameters after * are keyword-only
  • lets an API lock its calling convention and avoid positional misuse

Practical example

Python example
def divmod_safe(a, b, /, *, allow_zero=False):

forces

Python example
divmod_safe(10, 3)

as the call shape and rejects

Python example
divmod_safe(a=10, b=3)

, while still requiring

Python example
allow_zero=True

to be spelled out explicitly.

#functions#api-design

Sources

The Python Language ReferencePython Software Foundation · Precise scoping, evaluation order and expression semanticsWhat's new in Python 3.14Python Software Foundation · Current-version language and runtime changes, including template strings and free-threading support