Skip to main content

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.

A positional parameter is a function parameter that receives its argument based strictly on the order (position) in which the arguments are passed during the function call. The Python interpreter binds the arguments to the parameters from left to right. In a standard function definition, parameters are positional by default unless explicitly called with keyword arguments.
def assign_values(a, b, c):
    print(f"a={a}, b={b}, c={c}")


# Arguments are bound by their sequential position
assign_values(10, 20, 30) 

# Output: a=10, b=20, c=30

Positional-Only Parameters

Introduced in Python 3.8, the forward slash / syntax explicitly restricts parameters to be positional-only. Any parameter defined before the / cannot be passed as a keyword argument. This enforces strict API boundaries at the signature level.
def strict_positional(x, y, /, z):
    pass

strict_positional(1, 2, 3)       # Valid: all passed positionally
strict_positional(1, 2, z=3)     # Valid: 'z' is after '/' and can be a keyword


# strict_positional(x=1, y=2, z=3) 

# Raises TypeError: strict_positional() got some positional-only arguments passed as keyword arguments: 'x, y'

Arbitrary Positional Parameters (*args)

Python allows functions to accept an arbitrary number of positional arguments using the unpacking operator *. The interpreter packs all remaining positional arguments provided in the call into a single tuple bound to this parameter.
def collect_positional(first, *args):
    print(type(args)) # <class 'tuple'>

collect_positional(10, 20, 30, 40) 

# first = 10

# args = (20, 30, 40)

Syntax Rules and Constraints

When defining and invoking functions with positional parameters, the Python parser enforces strict ordering rules:
  1. Definition Order: In the function signature, standard positional parameters without default values must precede positional parameters with default values.

Valid

def func(a, b=5): pass

SyntaxError: non-default argument follows default argument

def func(a=5, b): pass

2. **Call Order:** During invocation, all positional arguments must be passed before any keyword arguments.
   ```python
def func(a, b, c): pass

func(1, 2, c=3) # Valid

# SyntaxError: positional argument follows keyword argument
# func(1, b=2, 3) 
Master Python with Deep Grasping Methodology!Learn More