Back to results for “Scope”
Python › Functions & Scope

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

Beginner

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.

Common follow-ups: Can you have a positional argument AFTER a keyword argument in the same call?