Skip to main content
A keyword argument is a value passed to a function by explicitly assigning it to a named parameter defined in the function signature. In Python semantics, a parameter is the named variable declared in the function definition, whereas an argument is the actual value bound to that parameter during invocation. Passing arguments by keyword binds the value to the parameter by its identifier rather than by its positional index.

Syntactic Rules and Evaluation

Order Independence Because the mapping is resolved via the parameter identifier, the order of keyword arguments in the invocation does not need to match the order of parameters defined in the function signature. Positional Precedence When mixing positional and keyword arguments in a single call, all positional arguments—including those provided via iterable unpacking (*iterable)—must strictly precede all keyword arguments. Violating this rule results in a SyntaxError.
Parameter Uniqueness An identifier can only be bound once per function call. Passing a value positionally and subsequently attempting to bind the same parameter via a keyword argument raises a TypeError.

Keyword-Only Parameters (*)

Python allows the definition of parameters that must be passed as keyword arguments. This is enforced by placing a bare asterisk (*) or a variadic positional parameter (*args) before the target parameters in the function signature.

Positional-Only Parameters (/)

Conversely, Python 3.8 introduced the forward slash (/) to denote positional-only parameters. Any parameters defined before the / in the function signature cannot be passed as keyword arguments.

Variadic Keyword Parameters (**kwargs)

A function can accept an arbitrary number of keyword arguments by prefixing a parameter name with a double asterisk (**). During execution, Python packs these unmatched keyword arguments into a dictionary bound to that parameter identifier.

Dictionary Unpacking

Existing dictionaries can be unpacked directly into keyword arguments during a function call using the ** operator. The dictionary keys must be valid strings. These keys must either match the function’s explicitly named parameters or, if the function signature includes a variadic keyword parameter (**kwargs), be captured by that variadic parameter.
Tired of Poor Python Skills? Fix That With Deep Grasping!Learn More