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
def divmod_safe(a, b, /, *, allow_zero=False):forces
divmod_safe(10, 3)as the call shape and rejects
divmod_safe(a=10, b=3), while still requiring
allow_zero=Trueto be spelled out explicitly.