Alright! So, let's talk about keyword arguments. The first keyword, or boolean, that we are going to cover is None. Basically, this is the equivalent to null in other languages. So, let's go ahead and write our previous function.
def print_something(name = "Someone", age = "Unknown"): print("My name is", name, "and my age is", age)
print_something(None, 27)
There isn't a way to pass in an argument that isn't first one being used unless we use keyword arguments. We can also define the variable when we call the function.
def print_something(name = "Someone", age = "Unknown"): print("My name is", name, "and my age is", age)
print_something(age = 27, name = "Nick")
By using keyword arguments, we can specify which value is supposed to go in a particular variable.
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.