Module 4 · How functions communicate with their environment · Lesson 3 of 5
Keyword argument passing
There's a second way to pass arguments that sidesteps the order problem entirely: keyword arguments. Instead of relying on position, you name the parameter right at the call, with name=value. Python then matches each value to the parameter you named.
area(height=4, width=3)Named at the call, each value finds its own parameter — so the order you write them no longer matters.
Because each value carries its own label, the order becomes irrelevant — area(height=4, width=3) does exactly the same thing as area(width=3, height=4). The keyword has to match a real parameter name, though, or Python will complain.
Keyword arguments also make a call read better: introduce(name="Ada", age=36) tells you what each value means without having to go look at the definition. So when do you use which? Often you'll want both at once — which has one small rule.