Kelly guys and welcome back to another class of our course about the complete introduction to Python.
We saw a lot of things in this course.
And since right now we are talking about functions.
I think that I think is very important about functions will be the return statement.
And for me this is something that is very important.
So what is exactly the return statement and how exactly can it work in functions.
Well it's very simple the return statement is simply a statement that is used to end the execution of
a certain function.
So what does this mean.
This means when you run the return statement everything that is after it will not be taken into consideration
and will not be printed in our function.
So let's say for example you want to end up a certain function at a certain place.
You simply enter your return statement and your function will end up at this particular place.
This works for a string.
This works for numbers.
This works for boolean it works for absolutely everything.
Let me show you a quick example.
So let's say we write down a simple function.
So in this case it will be a calculation function.
Let's say we have our calculation
and we'll have our elements.
That will be A B C grade.
So next thing that we want to do we'll write down our calculations so let's say we want to Python to
print some outcomes.
In this case we'll have a plus b plus c we want to print up
A minus B minus C
a multiplied by B and divided by c.
Good.
So right now our up is consisted of three lines of code.
And if we run our up in this case let's run it.
So calculation let's name our variables one two and three and let's run our up.
So when we run our up as you can see the answer will be six minus four and zero point 6 6 6 6 6.
All right.
So let's say for example we don't need those two lines of code right.
Well we don't.
The last line of code we just need the two first lines.
So what we'll do.
It's very simple.
We'll go at the same line and simply write down our written statement right here.
You can see we have our third line of code but everything will stop right there.
So we can run our up as you can see this will be our answer.
If we add for example a string let's say you print this is a calculation.
So if we add a string as you can see right there and run up it's going to still work.
But if we add a string after the return calculation the return statements are.
So in this case let's say we write down something and we run our up as you can see it still returns
us only the first part of the statement.
So in this case as so the return segment as I explained is very very useful in the case of if you want
to for example stop a function at a certain place.
So if for example you need only a certain part of a certain function at a certain place well you can
stop your function at a certain place.
For example it's a long calculation that is the draw function is a long calculation of as many steps.
So say for example you want to stop your calculation at the second step.
Well we can just put your return statement at the end of the second step and that's it.
It will not run what's coming after.
So in this case here we have our two steps so the first step will be to print a plus b plus c the same
step will be printing.
This is a calculation third step will be printing A minus B minus C.
And this is where we will stop our calculations.
Everything after this statement will disappear.
So wheel well will not disappear.
It will not be used in our function as you can see it's something that is very very useful and the key
is that if you want to for example cut your functions at certain places there are other things that
you can't.
Well there are other utilities.
The return statement.
But once again this is the main one and this is the most important one.
So let's say for the stats guys in C all in our next class.