Advertisement
Beginner Python, Functions & Scope

What is the difference between positional arguments and keyword arguments when calling a function?

Short answer

Positional arguments are matched to parameters by ORDER; keyword arguments are matched by explicit NAME (param=value), letting you pass arguments out of order and making the call site more self-documenting — a function call can freely mix both, positional first.

Save Python mock interview
Advertisement
AModel answer
Positional arguments are matched to parameters by ORDER; keyword arguments are matched by explicit NAME (param=value), letting you pass arguments out of order and making the call site more self-documenting — a function call can freely mix both, positional first.
def greet(name, greeting):
    return f"{greeting}, {name}!"

greet("Sam", "Hello")               # positional
greet(name="Sam", greeting="Hi")    # keyword, order doesn't matter
greet("Sam", greeting="Hey")        # mixed
Real-world example
Making a function call with many parameters more readable by using keyword arguments for less-obvious values.
Likely follow-ups
  • Can you have a positional argument AFTER a keyword argument in the same call?
Related topics