Syntax for defining a function.
If you observe the last statement in the function body is it a done statement.
And when a written statement is encountered inside a function the function dominate and the value of
the expression followed by the return keyword is sent back to the part of the program that called the
function and this expression within the square brackets is optional.
If you provide this expression by then evaluates this expression and returns the result.
Consider this example.
I have defined a function and which takes two arguments A and B and it has a print function and then
it don't statement in the function body.
And also I have defined another function some which takes two arguments and print the sum of these two
variables.
So let execute both of these functions.
Indeed you put a notebook.
So here I have defined this function which contains a written statement.
So let execute this
and as you can see the written statement has evaluated this expression and return the result.
Now coming to the next function some let's execute this code as well.
And the sum function has return the sum of these two arguments.
So what is the difference between the function add and the function sum.
These functions which returns values are known as value returning functions as functions which do not
return any values are called Wide functions.
So also a function that returns a value produces a value for use by the program or in particular for
use in part of the code ready function was invoked.
So what do we mean by that.
So in order to better understand this let's do one in order to make the.
It is the return value available to the program as it continues executing.
We can assign this function call to a variable so here I have assigned a variable to this function call.
And after you make the function call to this program the function gets executed and the value that does
it at dawn is assigned to this variable white and as a next step.
Letters modify or change perform some mathematical operations on this variable right.
So let's say let's multiply the variable y with minus 1 and then put in this variable Y.
So let's execute this code.
So as you can see that adorned value from the function has been saved to this variable Y and b have
performed some operations on this variable.
And then finally printed this variable.
Now let us do the same thing.
That means let us also assign a sign of variable Zi to the function call sum of 4 and 5.
So let's execute this.
So in order to understand the difference between a value the turning function and a wide function I
have assigned a variable to this function call.
So zi is equal to some of the variables 4 and 5.
And once we execute the code in this cell the number 9 that you see in the output is being printed using
this print function and then none is being printed using this print function so Zi has been assigned
a value none and all functions in that redefine in python have order done value even if there is no
return statement inside the code and functions without a written statement it on a special value note
NES none which is equal in two files and the interpreter does not print none so that is the reason when
we have executed this function so when you execute this function which has no order done state Min
the brain function displays defining the sum of these two variables but devalue none as not Red Dawn.
That's because the interpreter does not print none in this function.
I have omitted the expression in the return keyboard.
In that case when you execute this function in this code dysfunction you don't none nada to check that
you can assign this
the function call to a variable M that display m.
And if you check the type of this variable m it is of D data type none type.
The variability has been assigned none because the print function does not assign a value to a variable
and it does not return a value from a function called and that is the reason the variable G has been
assigned the value none.
We can also have multiple written statements inside the function but as soon as the first return statement
has encountered the function terminate and all these statements following the written statement are
not executed.
So let's see this example.
So we have the if elif added statement here and each of these statements contain the return statement.
So when we execute this function after one of the conditions becomes true the written statement is executed.
And all these statements following the written statement are not executed.
So when one of these conditions is true the return statement within that condition get executed and
the function terminates and all these statements following it are not executed and a written statement
can also return multiple values from a function.
So in order to do that you can separate each of these expressions here with a comma.
So let execute this code.
So a tuple is written in case you want to have the result saved in different variables.
You what you can do is you can defined three different variables C L comma and comma n and assign these
variables to the function call now and then let print each of these variables.
In and then M and in so as you can see the the return value from each of these expressions inside the
return statement have been saved in the variables L M N and and this is about the return statement.