The function you have seen in the previous lesson is very simple,
and it will do the same thing every time you call it,
which is just to print hello, and then, well, let's just remove that.
So it's just going to print hello every time you call the function.
Now you can add parameters to a function.
A parameter is simply a variable you are going
to pass to the function when you call it.
And then inside the function, you can use this variable to do anything you want.
And let's see this with an example. Let's continue with our say hello function.
Let's say we want now to say hello with the name.
So we want to pass a name to the function to say hello to that name.
I'm going to add a parameter here, user name.
So this is going to be a variable inside the function.
And now I can use the variable in the function, for example, hello plus user name.
So as you can see, I can reuse the parameter.
So this is a variable. This is the same thing.
I can reuse the parameter I got in the function directly
inside the function, inside the execution of the function.
Now if I run this, I'm going to have an error.
Why is that? Because here I am calling the function say hello,
and you can see missing one required positional argument username.
Actually, let's remove this. Let's just call it once.
Okay, so say hello. The thing now is that there
is no function say hello with zero parameter.
There is one function say hello with one parameter.
So I need to give it a parameter. And here I'm going to give it a username, Bob.
So say hello, Bob. And then Bob is going to be passed as a parameter here,
and we can use it in the function. Let's run that.
Hello, Bob. Okay, so that is very convenient.
Now what I can do is I can do say hello.
So I can use the autocompletion here, and let's say John.
And as you can see, hello, Bob, and hello, John.
So we have the same exact same code for the function,
but with the parameters, we can make it more dynamic.
Okay, depending on what we pass in the parameter,
the execution of the function would be different here.
And of course, you can add as many parameters as you want.
Let's say you want also the user age.
So I can do hello username, and then plus comma, you are, and then plus user age.
So now those two functions are, those two
calls to the functions are not correct anymore,
because now we need to pass two parameters.
And the order is very important.
You need to pass the first user name and then the user age.
So Bob, and let's say 45, and John, and let's say 42.
I'm going to run the main, and you can see we have an error.
Okay, and this is why this is a cast error.
You can only concatenate string with string and not integer.
So here we have a user age that we just concatenate with this string.
The problem is that we pass an integer here.
Okay, that's quite normal because that's a user age.
So what do we need to do in the print function?
We need to cast this integer into a string.
So we need to call the str here.
We need to cast to str inside this username.
We didn't have the error before because we pass a string.
So this we know this is going to be a string.
This might be an integer, so we are going to cast it to string.
Now I run it, and it's going to work.
Hello, Bob, you are 45.
Hello, John, you are 42.
Okay, so you can make this function much more complex with many lines of code,
and then you can call it as many times as you want.
And with different parameters, you are going
to have different code executions, okay?
But you just need to write the function once, and that's it.
So to recap, with parameters, you can make your functions more dynamic.
With just one block of code in a function, you can repeat a set of instructions with
different values any number of times you want.