loop
How functions communicate with their environment

Module 4 · How functions communicate with their environment · Lesson 4 of 5

Mixing positional and keyword

You don't have to choose one style — you can mix positional and keyword arguments in a single call. It's common to pass the first, obvious value positionally and then name the rest for clarity. There's just one rule, and Python enforces it strictly.

The rule: every positional argument must come before any keyword argument. Once you've started naming arguments, you can't go back to bare positional ones — Python would no longer know which parameter the bare value belongs to.

Positional first, keyword after
greet("Ada",greeting="Hi")✓ positional, then keyword
greet(name="Ada","Hi")✗ positional after keyword
SyntaxError: positional argument follows keyword argument

The good arrangement reads naturally; the bad one stops the program before it even runs, with a SyntaxError. The fix is always the same: move the positional arguments to the front, or give them names too.

Run it yourselfruns in your browser · Python
main.py

That's the complete picture of passing data into a function: parameters as slots, arguments by position or by name, and how to combine them. A short quiz to lock it in.