Keyword arguments in functions

Keyword arguments are name-value pairs specified in the function call. With keyword arguments, you don’t have to worry about the order of the arguments because you explicitly specify which parameter each argument should be matched with.

Let’s rewrite the example from the last lesson:

def describe_me(name, gender):
    print('My name:', name)
    print('My gender:', gender)


describe_me(gender='M', name='Tuna')

>>>
My name: Tuna
My gender: M
>>>

We’ve explicitly specified the parameter-argument pair during the function call. Notice how we’ve specified the gender parameter first, although it comes second in the function definition. As stated above, the order of the arguments in not important when using keyword arguments.

Make sure that the parameter names match the values used in the function call.
Geek University 2022