Posted on

Keyword Arguments in Python

Enroll in The Complete Python 3 Course: Beginner to Advanced!

Click here to subscribe for more videos like this!

Alright guys so let’s talk about keyword arguments. In the last video we found out how we can pass only one parameter into a function if we have the other one set up with the default value. So, this will allow us to pass the first argument only there’s going to be no way to omit this and pass the age, so let’s do this. Let’s run it and it’s going to say my name is 27 and my age unknown. Now there is another keyword in Python called “none” just like this, this would be a Boolean I guess or just a keyword in general, basically this is the equivalent to null in other languages. So we’re going to save this and run this again, and it’s going to say my name is none and my age 27. There’s literally no way to only pass in an argument that is not the first argument unless you use keyword arguments, and that is defining what variable this is supposed to be. So if we do this and hit run we’re going to see that my name is someone, because we didn’t define a name, and my age is 27. Now we can also use this capacity and parameters in different orders. So I can say name “name=Nick” there let’s save that and run it and you’ll see that the order we’re passing it in it should if we weren’t using keyword arguments would say my name is 27, and my age is Nick. So, by using keyword arguments we can specify which value is supposed to go into which variable, when it goes into the function. So that was actually pretty quick. That’s keyword arguments and how to use them. I kind of like the sister concept of default arguments. So in the next video we’re going to be talking about an infinite number of arguments.