‫In the previous videos, I showed you how to define a function with parameters.
‫Now, the way I've shown you this and these parameters is what we call positional.
‫Parameters, or we might want to call them positional arguments and they're called positional arguments
‫because the position matters, right?
‫If I change our arguments to, let's say, Andre as the second argument and if I click run, you see
‫that I get Hallo Smiley Face Andre, which maybe is not what we want it to do.
‫Positional arguments are arguments that require to be in the proper position.
‫So if we defined name here first and then emoji second, you have to make sure that the first argument
‫will be the name and the second argument will be the emoji.
‫However, there's something called.
‫Key word arguments.
‫And keyword arguments allow us to.
‫Well, not worry about the position.
‫What do I mean?
‫Well, I can do something like this.
‫I can say say hello.
‫And in here, give it a keyword and a value.
‫So I'm going to say emoji equals to, let's say, this smiley face.
‫And then comma name equals to Bibi.
‫Now if I run this.
‫You'll see that I get.
‫Hello, Bebe.
‫Because I was able to use keyword arguments.
‫I tell it explicitly, Hey, I want emoji to be this and name to be this.
‫So positional arguments these matter but keyword arguments.
‫It doesn't.
‫Now I argue that this is bad practice because you're making the code more complicated than it needs
‫to be.
‫If the definition of the function is to give name an emoji, you should follow that practice and not
‫confuse other developers.
‫Then just stick to that name and emoji so you can still use keyword arguments, but make sure that they
‫are in order because why wouldn't you just follow what the function tells you?
‫It's the same result, but at least this way you are following well, the standard flow.
‫And by the way, these keyword arguments can sometimes be confused with what we call default parameters.
‫I know it can get really, really confusing, but this is something that will come naturally to you
‫after you practice a little bit.
‫So I'm going to just comment this out and show you how default parameters work.
‫Default parameters.
‫Allow us to give right in here as we're defining the function what we want as default in this.
‫In our case, let's say.
‫Darth Vader is the default name and the emoji will be.
‫This little angry Darth Vader?
‫Well, it doesn't really look like Darth Vader.
‫But this is the emoji that we were going to use.
‫So what does this do?
‫Well, if I run my program.
‫Everything works the same if I do keyword arguments and run my program.
‫Nothing changes.
‫Let's make this a little bit bigger.
‫However, default parameters allow us to do something interesting.
‫For example, if I run.
‫Another function.
‫Say hello, but I forget to give it parameters or arguments in our case.
‫Well, if I run this.
‫I get.
‫Hello?
‫Darth Vader.
‫Because with default parameters, it says if you're not able to get name in emoji because you are called
‫without any arguments.
‫Well, in that case, make default Darth Vader and make default emoji.
‫This little emoji.
‫If I use, let's say, just.
‫One argument and I click Run.
‫Then well, it will fill that name variable, but anything that we don't give it like emoji will be
‫predefined.
‫So this is a great way to make sure that your function runs, even if it's called the wrong way.
‫So keyword arguments increases the readability of your code because you know exactly how we're calling
‫say hello and default parameters allow us to keep our functions a little bit more safe because we make
‫sure that when we use a variable, we're going to have a no matter what, regardless of how it is being
‫called.
‫But positional arguments are also useful because it's nice and clean, right?
‫We're just following what the function tells us to do and it's easy to read.
‫So there's pros and cons of using each.
‫But I hope this demonstrates to you some of the ways that you can define functions and also call functions.
‫I'll see you in the next one.
‫Bye bye.