Hello, everyone, in this session, we will discuss about functions, so first of all, let us see
what is the need of creating a functioning.
So let us look at this particular piece of food that I have created, a list of numbers.
The list contains numbers from one to seven.
I have created a variable which has value, and I'm iterating on double this number list, which will
retrieve one number at the time.
And then I'm adding the number to the desired so that I get the value as a sum of the entire number
list.
So let us print the result, which is intermediate.
Let us see the intermediate results until.
So here you can see the number is additionally zero, it added the value one to it, then it added the
value to three and four so that it adds all the values together.
And finally you get twenty eight as a result.
So we are getting a some of the value of a set of numbers here.
Now this is just one scenario, so let us think what will happen if you want to do the same addition
operation several times so would be writing this entire piece of food.
Again and again that is not really feasible and that would not be even more feasible when we have a
very long piece of wood, which you want to use again and again.
So in this particular situation, we will be using functions.
These functions will help us to run a particular piece of food.
Again and again without the right thing, it.
So let us see what the functions of function is, an independent and reuseable block of food, which
you can call any number of things from any place in the program.
So I need not read this particular piece of food just when I want to live.
I can create it whenever I want.
It can be present anywhere in the program and I can call it whenever I want to eat.
It is an essential tool for programmers to split a big project into smaller modules.
Now, how is it also useful?
That is, if I want to use this particular code again and again and I want to store it somewhere so
that it is more simpler to see, then I can use a function.
So let's see how a function would be created out of this.
So to create a function, we can get this entire Diaco.
So to begin with the function, we will need the definition giver, which is this, this means that
we are starting to define a particular function.
Then we give a function name.
So let's say we want to create a function for adding.
So we are seeing naming it either.
After that, in the round bracket, we need to give the argument which will be given to it the input
parameters, so this entire function will work on the no list, which will mean we will be providing.
So we will mean no list.
You can name it anything other than the colon, which would mean that the definition of the function
is starting now.
We will give the indentation without indentation.
It will not understand that the food which we are about right now is a part of this entire function.
So let us start writing the code.
So in this particular piece of code, we will need the number list again, but we already have it.
So we don't really need it now because it has already been defined.
Now, each time the function will run, we would have to meet the value of the desired.
So that is the reason why we will put it equal to zero here.
Then we will need the entire I don't.
So this is the entire piece of code now.
We don't really want to bring in the media results because we want this to walk silently.
I'm just giving them to us so we will not bring that here.
Now, these intermediate results, we will not be printing now.
It will again be invented because this result is a part of this Falu.
And the sprint is the final sprint.
Now, if you want to run this, so for this post, we will shift and this means that that function has
been defined.
Now the definition has been completed, the function has been created, but we have not really called
the function now without calling the function, it will not run.
So, two, done this function.
We will have to foil it.
So we will see this.
I we will give the no list again, so we will see novelist.
Now, if the shift into this will run the Diaby support, which was a part of this definition and give
us the desired, because we have already asked it to frame the desire for expanding the desire for us
now if we don't ask it to bring the desired.
So we will have done this again once we did this and then when we done this, it will not give any result,
although it has completed running.
Now let us say we don't really want to predict the result, but we want to use it for some other.
So what we can do is instead of pretending that we can simply resume the research,
so when we see the dome, that is once this function would run, it will return a particular value to
us.
So let us see.
Let us run this.
Now, what we can do is we can either print that is out that we can, which we get from the Idaho.
So here we can do this or we can simply take this into a variable.
And we can use it later, such as the last five, and we just want to print.
And let us bring virosome.
So here you can see we can use the value statically after returning it from the desert.
Now the name which we have given in the definition need not really be the exact name which we will be
using here, the name which will be coming to the function so it can have any value.
So let's say it is an.
OK, so when we see those in, it will still walk the same way.
It doesn't make any difference.
Now, let us see another thing, let us try to create another function which will add multiple input
values.
So let us define another function.
Let us call it either do I'm in this.
We are taking numbers I g so we are taking two numbers and I enjoy.
Now, if you can say that here, we are not giving any particular data.
So this means that it can take any time and it will automatically understand the data to be whatever
we are providing.
Now we see a dissolve is equal to zero.
Now instead of dissolved equal to zero, we can simply not give a definition to result because we will
be anyhow adding these two numbers and we can see a desired.
Is equal to.
We will have to give just a single indentation result is equal to.
I love you and we concentrated on you.
Now, I want to call it, I will say I do and I will, given the numbers here.
And when I ran this.
It will return the some of these values.
Now, another thing, what I can do is instead of writing it this way.
I can return this directly so I don't have to create a new variable result for this.
And it will we'll just see.
So this is about functions now, using the same time I'm using similar process, you can create a much
complex function and use it in your project.
Thank you.