Hello and welcome to this video.
What is a default parameter valid.
This is the value that a function uses when it is called.
Without passing it a value.
So when you call a function without a parameter it uses the default value only parameters at the end
of a parameter list can have a default value.
This is because the values are assigned by the position.
So if you have several parameters you can only give the last parameter in the list a default value in
the first example here.
Now this is a proper way of assigning a default parameter value because this has two parameter parameter
a impairment to be because of the way the values are assigned by the position.
You can only give a default parameter value to the last Parliament inside the function definition.
So this is the proper way.
And this one is not the right way because you see him giving it a default value here when he should
be at the end of the parameter list.
Let's create a new function.
So I'm going to create a function called student on the score names and inside the parenthesis I'm going
to define just one default value.
So I'm going to call it names names is going gonna be the parameter.
I'm going to use the equals to sign to assign a value to the parameter.
I'm going to call it blue line so that is the parameter names.
And this is the default value.
So I had my colon and tab and I'll start a new line of code.
So inside my function body I want to add a print function inside that print function.
I want the print function to say hello plus the student's name.
So I.
Which is to a space and add a addition operator and then add the name of my parameter.
So my parameter here is called names.
So what I'm saying once I run this code any values are passed to it.
It will print out Hello plus whatever name I passed to the function.
So let's try and call the function and pass it some arguments to call the function you call the function
by its name which is call student on the score names and then inside the parentheses I can pass in different
names.
So let's say for this one I am going to leave it blank.
I'm just gonna copy this a couple of times.
So inside the names I'm going to add in some strings because your strings.
You need to enclose it in quotes.
So the first one here I'll say John.
And for this one here I'm going to add Jane right.
So notice the first one here.
Line number five.
I have not passed in any value.
So what's gonna happen when I execute this code is going to use the default value that I have set inside
the perimeter here that I defined so let me save my code by pressing control an s. If you are a Mac
you can do command an s.
So once you've saved you could play the file.
So I click on play and you can see the output when I call the function.
I did not pass in any value for the first student name and it then used the default value which was
blue line.
Line 6.
A pastor named John it says hello John.
Line 7 passed in the name Jane.
It says Hello Jane.
So inside the function body I did say I wanted to print the word hello plus whatever names I have supplied.
So the names of supplied when I called the function.
While John again I didn't supply a name for blue line because blue line here is a value the default
parameter value for these names variable.
So that's basically how you use parameter default value.
The key thing to note is that where you have several parameters defined you can only give the default
value to the last parameter in the list.
So if you have several parameters you separate them by a comma and you can only add a default value
to the last one.
This is because of the positioning.
Okay.
The values are signed by position.
That's it.
Thank you for watching and bye for now.