Great, you can now create functions, call them,
and add parameters to make them more dynamic.
And now what you can also do is to make a function return a value.
So this function, SayHello, is just a function that does an action.
It doesn't return anything.
Now I'm going to create a new function.
So as you can see, when I just press Enter here, I still have the indentation.
So what I'm going to do, I'm going to remove that indentation and do depth again.
So let's say I'm going to create a function, double number.
And let's say, hey, or just number.
So you can create as many functions as you want.
You just need to put them one after the other.
Okay, so now I'm going to create a function with one parameter.
And the name of the function is double number.
And I simply want to return the double for this number.
So I'm first going to compute the result, which is the double of that number.
So I'm going to create a variable result is equal to number times two.
And then what I'm going to do, I'm going to use the return statement.
Return result.
So what this function will do when it's called,
so first it's going to receive a parameter number.
It's going to compute the double of this number and return the result.
So when you call the function, you can get the double of the number you send.
Just before we continue, one thing I'm going to do here
is that so we create a variable and we just return that variable.
So basically, we are not going to use that.
We only return that variable.
So what I can do instead of result is equal to number times two and return result,
I can just return number times two and remove that.
So this is going to return directly the correct value.
And now, well, I can call this function.
So I'm first going to put a comment here.
Okay, so we don't call those.
So this is not a problem.
You could call this and call this.
That's not a problem.
Here, I just want to call that function and not this one.
So we just have less lines in the output.
So what I can do, I can do double number.
I can use the auto-completion with, let's say, three.
Okay. And I'm going, of course, to store that.
So let's say number is equal to double number three and then print number.
So when you create a function that returns something with a return statement,
when you call the function, you can actually
assign the value you get here to a variable.
And then you can print, of course, the variable,
or you can do whatever you want with the variable.
So I just run the program and you can see I have six.
So the double of three is six.
So the number variable here contains the value six.
All right. So you can see two types of functions here.
So those who are just going to do an action and don't return anything,
and those who compute or maybe get a value from somewhere and then return that value.
Note that you can return any kind of value you want.
Here, I return an integer number.
But you can return a float, a Boolean, a string, list of whatever you want,
while just return what you want from the function.
But just make sure that when you call the function,
you actually know what kind of data type you are going to get.
Okay. And one thing you can also do is you
can call a function inside another function.
And thus, you can really make functions as building blocks
that allow you to create even more building blocks.
Let's see that with an example.
Def print double number.
So with number, and I'm going to do result is
equal to double number of the number we get here, and then print result.
Or maybe make it better.
So double of plus the number casted as a string, plus
is, and then plus the result also casted as a string.
So when you call this function, what it's going
to do is going to call the double number function.
Okay. So from the function, you call another function.
And you can see this parameter I got here,
I'm going to pass it also to the double number function.
And then I can print some stuff with the parameter and the result I got.
And I'm going to call it this print double number.
I'm going to remove that.
And I'm going to remove that.
And I'm simply going to run.
And you can see double of three is six.
Okay. It's all happening in that function.
So here you have a function that just does an action and that's it.
Here, a function that returns a number.
And here, a function that does an action, but
inside, you actually call another function.
And you can create another function that is
going to call that one, et cetera, et cetera.