100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Python

Function Arguments in Python

Understanding positional, positional-only, keyword-only, *args, and **kwargs arguments in Python function signatures.

FunctionsIntermediate9 min readJul 7, 2026
Analogies

1. Introduction

Python offers flexible ways to pass data into functions. Arguments can be matched to parameters by position, by keyword name, or collected into variable-length containers using *args and **kwargs. Understanding these mechanisms lets you write functions that accept a fixed set of inputs or an open-ended, flexible set of inputs.

🏏

Cricket analogy: A captain can set a field by naming positions explicitly, like 'gully' and 'mid-on', or just by pointing fielders to spots in order, and can also leave open slots for extra fielders to fill in as substitutes come and go.

Python also allows you to restrict how arguments may be passed using positional-only markers (/) and keyword-only markers (*), which improves API clarity and prevents callers from relying on internal parameter names.

🏏

Cricket analogy: A tournament might mandate that overseas players can only be named by their registered slot number, not swapped freely mid-season, while a domestic wildcard pick must be named explicitly by the selectors, never assigned by default order.

2. Syntax

python
def function_name(pos_only, /, pos_or_kw, *, kw_only):
    pass

def flexible(*args, **kwargs):
    # args is a tuple of positional arguments
    # kwargs is a dict of keyword arguments
    pass

3. Explanation

Positional arguments are matched to parameters in the order they are passed. Keyword arguments are matched by name, regardless of order, using name=value syntax. A single * in the parameter list marks the start of keyword-only parameters; a single / marks the end of positional-only parameters (available since Python 3.8).

🏏

Cricket analogy: Naming a batting order 'opener, one-down, three-down' matches players to slots by their listed order, while calling out 'finisher=Dhoni' matches by name regardless of where he's listed; a single declared cutoff role like 'all specialists after this point bat only lower order' marks a boundary in the lineup.

*args collects any extra positional arguments into a tuple, and **kwargs collects any extra keyword arguments into a dictionary. This is commonly used to write wrapper functions or APIs that forward arguments to another function without knowing the exact signature in advance.

🏏

Cricket analogy: A team manager collects any extra last-minute net bowlers into one flexible practice squad without naming each individually, and separately gathers any extra logistics requests, like transport or catering, into a labeled request list — useful when forwarding needs to the ground staff without knowing the exact count in advance.

*args and **kwargs must appear in a specific order in the parameter list: standard positional parameters, then *args, then keyword-only parameters, then **kwargs. Placing them incorrectly raises a SyntaxError. Also remember *args is always a tuple and **kwargs is always a dict, even if you only pass one extra argument.

4. Example

python
def describe(a, b, /, c, *, d):
    print(a, b, c, d)


describe(1, 2, 3, d=4)


def summarize(*args, **kwargs):
    print("args:", args)
    print("kwargs:", kwargs)


summarize(1, 2, 3, x=10, y=20)

5. Output

text
1 2 3 4
args: (1, 2, 3)
kwargs: {'x': 10, 'y': 20}

6. Key Takeaways

  • Positional arguments are matched by order; keyword arguments are matched by name.
  • The / marker makes preceding parameters positional-only; the * marker makes following parameters keyword-only.
  • *args gathers extra positional arguments into a tuple.
  • **kwargs gathers extra keyword arguments into a dictionary.
  • Parameter order in a definition must be: positional, *args, keyword-only, **kwargs.

Practice what you learned

Was this page helpful?

Topics covered

#Python#PythonProgrammingStudyNotes#Programming#FunctionArgumentsInPython#Function#Arguments#Syntax#Explanation#Functions#StudyNotes#SkillVeris