Python keyword arguments

You will remember from our beginner’s tutorial that we had a discussion around methods and we they are an important construct of python and other programming languages. I wanted to share with you guys a cool python tip to add to this knowledge.

Logitech MK550 Wireless Wave Keyboard and Mouse Combo — Includes Keyboard and Mouse, Long Battery Life, Ergonomic Wave Design – $43.50

If you recall, method arguments are typically called directly into the method call in the order in which the arguments or input parameters are found in the method definition. Take this sample method for example:

def example(input1, input2, input3):
print(input1)
print(input2)
print(input3)
print(input4)

Lets say you make the method call like this:

example(1,2,3)

It’s implied that you want input1 = 1, input2 = 2, and input3 = 3. Now lets do this using python keyword arguments:

example(input1=3, input2=1, input3=2)

Pretty easy huh? All you’ve done is explicitly defined what you want the arguments inside of the method to be set to. This is what python keyword arguments are.

Start Your Career as Freelancer – Learn How

Leave a comment