Glossary

Parameter

A parameter (or formal parameter) is a name listed in a function's definition that acts as a placeholder for the value that will be supplied when the function is called. The term is often confused with argument, which refers to the actual value passed at the call site. In def greet(name):, name is the parameter; in greet("Alice"), "Alice" is the argument.

Python supports a rich vocabulary of parameter types. Positional parameters are matched by position. Keyword parameters can be specified by name at the call site. Default parameters have a fallback value if no argument is provided. The special *args parameter collects extra positional arguments into a tuple, and **kwargs collects extra keyword arguments into a dictionary. Python 3.8 introduced positional-only (/) and keyword-only (*) parameter separators for fine-grained API design.

One important caveat is that mutable default arguments are evaluated once at function definition time, not at each call. This means that def f(items=[]) will share the same list across all calls that do not pass items. The standard idiom is to use None as the default and create a new mutable object inside the function body.

Related terms: Argument, Function

Discussed in:

This site is currently in Beta. Please email Chris Paton (cpaton@gmail.com) with any suggestions, questions or comments.