-: 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, Andrei
as the second argument, and if I click run,
you see that I get, hello, smiley face, Andrei.
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
keyword 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 Bibi.
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 and 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 are gonna 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 and emoji
because you are called without any arguments,
well in that case, make default Darth Vader,
and maybe 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 pre-defined.
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 gonna have it 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.