Skip to content

Reference Documents

PDF versions of the content in the binders we have in class:

Explanation of Positional vs Keyword Arguments in Python

When you call a function in Python, you can give it values in two main ways:

  1. Positional arguments – the order matters.
print(10, 20)   # 10 is the first argument, 20 is the second

Here, Python knows which value goes where just because of the position.

  1. Keyword arguments – you say exactly which parameter should get the value, using the parameter’s name.
print(10, end="!!!")  

In this call, 10 is still positional, but end="!!!" is a keyword argument. You don’t have to remember its position, because you’re labeling it.


How they work together

  • Positional arguments must come first in a function call.
  • Keyword arguments come after positional ones.
  • Mixing them is common:
pow(2, 3)            # both positional → 2^3
pow(2, exp=3)        # mix → 2^3
print("Hello", sep="-")  # mix → "Hello"

So:

  • Positional = order matters
  • Keyword = names matter

Both are just ways of telling Python which value should go to which parameter.