Skip to main content
Positional-only parameters are function parameters that must be supplied strictly based on their order in the function call, explicitly prohibiting the use of keyword arguments (e.g., name=value) for those specific parameters. Introduced in Python 3.8 (PEP 570), they are defined in a function signature using a forward slash (/). All parameters declared before the / are enforced as positional-only. Parameters declared after the / retain standard Python behavior (they can be passed by position or by keyword) unless further modified by other signature operators.

Syntax

Mechanics and Behavior

When a function is invoked, the Python interpreter maps the provided arguments to the signature. If an argument corresponding to a positional-only parameter is passed using keyword syntax, the interpreter raises a TypeError.

Signature Composition

The / operator can be combined with the * operator (which enforces keyword-only parameters) to create a strictly partitioned function signature. This establishes clear boundaries for argument resolution:
  1. pos_only: Must be passed by position.
  2. /: Demarcates the end of positional-only parameters.
  3. standard: Can be passed by position or keyword.
  4. *: Demarcates the start of keyword-only parameters.
  5. kw_only: Must be passed by keyword.

Default Values

Positional-only parameters support default values. However, standard rules apply: a non-default positional-only parameter cannot follow a default positional-only parameter.
Tired of Poor Python Skills? Fix That With Deep Grasping!Learn More