Normal arguments vs. keyword arguments
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In Python, the difference between positional and keyword arguments is mostly about how values are matched to parameters. Positional arguments rely on order, while keyword arguments rely on parameter names, and understanding that distinction makes function calls easier to read and function signatures easier to design.
Positional Arguments
With positional arguments, Python assigns values based on their order in the call.
Here, "Maria" goes to name and "Hello" goes to greeting because of position, not because of the variable names in the call.
Positional arguments are concise and natural when the meaning is obvious from the order.
Keyword Arguments
With keyword arguments, you name the target parameter explicitly.
Because the mapping is name-based, keyword arguments can appear in a different order and still work correctly.
They are especially useful when:
- A function has several parameters of similar type
- Some arguments are optional
- Readability matters more than brevity
Mixing Positional and Keyword Arguments
Python lets you combine both styles, but positional arguments must come first.
This is valid because the positional values come before the keyword argument.
This is invalid:
Once you start using keywords in a call, you cannot add a plain positional argument afterward.
Why Keyword Arguments Improve Clarity
Consider a function call such as:
Without reading the function signature, the True and 3 are not very informative. Keywords make the call self-documenting:
That is one of the main reasons keyword arguments are common in APIs with many optional settings.
Positional-Only and Keyword-Only Parameters
Modern Python also lets function authors control how arguments must be passed.
In this signature:
- '
aandbare positional-only because they appear before/' - '
verboseis keyword-only because it appears after*'
This is useful when designing stable APIs or preventing ambiguous calls.
Defaults Work Especially Well With Keywords
Keyword arguments become even more useful when a function has optional parameters with defaults.
The keyword form makes optional behavior obvious at the call site and avoids memorizing the exact position of every flag-like argument.
Common Pitfalls
- Passing many positional arguments of the same type makes calls hard to read and easy to mix up.
- Using the same parameter both positionally and by keyword causes
TypeError. - Forgetting that positional arguments must come before keyword arguments leads to syntax errors.
- Overusing keywords for tiny, obvious calls can make code noisy instead of clearer.
Library APIs often reserve keywords for the parameters where the meaning is least obvious, which is a useful design habit to copy. That improves call-site readability quickly.
Summary
- Positional arguments are matched by order; keyword arguments are matched by parameter name.
- Keyword arguments improve clarity when function calls have several optional or similar-looking values.
- You can mix both styles, but positional arguments must come first.
- Python also supports positional-only and keyword-only parameters when API design needs stricter rules.

