Welcome to this lecture in this lecture we're going to learn about the fund since so we're going to
make our own funds and in this lecture but just remember we have made use of the fund since in bill
to fund science of the python.
Couple of times in the earlier lectures too.
So if you just remember about the modules that is at end random module let's go to the documentation
again.
This space F1 or just go to the help in the space despite the docs go to the modules Part A Random r
for random and see the random.
So all of these is your methods are the functions.
So if you made use of these renderings This is your fun functions.
If you see round into this is also your fun science.
So we are making use of this inbuilt fun sense of these python you are making use of input method which
is the inbuilt fonts and you have made to use a print.
We have made use of so many times to print.
It is also inbuilt fun and we have made use of Raines method in the previous celexa which is going to
return a strange object.
This is also the inbuilt function.
So let's create our own funds and now.
So first of all before creating our own fund since think why these funds and is essential.
So that would be because we don't want to repeat yourself so which is your great principles.
So what great principle says is Don't repeat yourself.
If you want to do the same tax why you are creating the same chord again and again this make a chord
in a way that you can call that whenever you need the same chord to be executed.
So let me say something like before creating any function so let me say I want to add three and four.
So I'm just giving us logic over here why this function is important.
So I'm saying I want to create a program that will just add 3 and 4 every time.
So in the funds and invest very much we are just making a program like it was making a program where
we see that whenever we just want to loans are this make a product.
We have to call that is the addition of three and four.
So instead of just writing three plus four every times you have to this says something like print to
me three and four first time and if you want to do again in the next module you have to say something
like three four and four.
Again the same court has to be repeated again and again if you want to do same tax which is edition
of three and four multiple times so instead of doing this what if we just create a method out of funds
on which will do the same tax and instead of just writing this quarter again and again we can just call
that funds and to do the same tax whenever we need it.
So let's see.
So first of all I would say ad this is going to this do some okay some getting some ad or basically
ad to the four to three ad number.
Okay so I'm getting the idea over here that it is the funds in and give the column and over here I'm
going to add three and four.
So now we have created a fund center which is going to do only one thing that is adding a three and
four.
Every time we call these funds and so calling is with the name only with this positive name we passed
apprentices.
And just give this our name.
If I saved this alone at five with a five it is going to give us seven so every time it is going to
give us seven.
So instead of just writing again this print now we can simply do these and then we can simply call these
and random and it will just execute the same codec in beginning.
So it is suing us seven and seven again.
So if you want to use this again four times or five times no problem.
This call is you don't need to write code again and again.
So it should seem something like for you.
That is OK.
This only one line code.
So what if we have a thousand lines of code away.
So instead of writing 10 thousands line of code again and again you can simply call that method which
will be executing that thousands line of code so this will just implement our great principle from these
Python implementation subdivisions since.
So now what you need to do is simply create a function which will this do something for us.
So to do that said Dave Dave is the defined cure which is usually used in the case of Python.
So we'll see the info mean for is my function.
And you just give this pattern this is denoting that this is the function.
So what here what in to do is just print I like OK.
And you know this is the way to format and I hate.
OK.
I don't hate what I normally type here over here and I'll just format using this format keyboard and
let's see we don't have anything to format it.
Let's go down and calling for ending this in full.
I want to parse this string name is Python and Java OK.
So you're are seeing here that we have parsed in disinfo so info has been called these funds and has
been called and we are just passing to string over here Python ends advises string.
But if you see in this info we don't have anything that is placeholder for this python in Zambia.
So this is where we just pass a parameter over here.
So if I say eco might be python will be in this a Java will be in this B.
So now we can format with this A and B.
So let's close this save this place up five you'll see I like Python and I a heads up.
It's not the case I like Zorba do what I'm just saying I heads away way.
So what we just did here was we just paused.
The argument is a bad imitation dysfunction in here.
What if I want to just remove this double and if I say this and press your five it is going to give
us a either saying missing one required to put this null argument to be.
So what we need to know over here is this in B over here is a positional argument.
So if we just pass anything in this field you have to bust is a position.
So if you don't pass it is going to slow us either.
So if I say down first and if I say Peyton you'll see the complete opposing meaning of what we just
expect.
So save this press.
The neatest thing I like Darwin I hate python which is obviously not the case but this Java will be
not in b now it will be in a.
So it is a positional argument.
So the order matters over here.
Whatever you pass first will be in this position argument which is the first is argument.
Second will be Call goes to the second.
If it is passed any thought of where it will go to the C if is a spouse something is argument away.
So the order matters over here.
But what if I say something like Python.
If I remove this it is still going to source.
That is it is required to have the one put this argument B but instead of this parsing from here I want
to pass as a default argument al-Sayed salvo by A.
Now you have the excuse and if I just print two they are five it is going to give us that I like Python
and I had Zorba because we have now default argument we have passed this default argument if we don't
pass it over here.
It will work is a default.
So this is a work of default argument but if you pass Java over here and if we just leave this b it
is not going to work.
So just remember that the argument will be default to default arguments would always be over here at
the last.
So it has given a cedar swing that Norton default argument follows a default argument that means no
default should be at first and that should follow by the default argument.
So default arguments should be always at the last.
So this should be a default argument and non default argument should be at the beginning.
So this the way to execute our method.
So next thing is to return.
So let's see this is a print what I want to do is say written mean.
This is string by formatting and now because it is returning something I'll just get over here so I'll
see info has been cast and lists print this info.
If I save this place F5 it is going to give us I like Python and I hate Java because we are just returning
something from the ones and because we have written something is to be cats over here where we just
call our Bunsen and we have this printed that masses which is returned from the Bunsen.
So this is the written keyword which is going to return as the value so if I see something like return
me for and addition of six and as I say printing for save this it is going to give us stain because
it is returning the addition and it is thus saving a here that is dead and we are just printing this
value is it in so this is our fun since so we can just create this funds.
Give the day cured funds a name and he said the bad indices if you want to have any argument which is
the default argument or non default argument just pass possible here and make use of the court inside
of this function and calling the funds in.
Is there another part with these barometers you want to pass to that argument which is used while defining
the fund since.
So next thing is to see the lambda for instance and they they're also called the anonymous functions
in the python so lambda functions can have any number of argument but only one expressions.
So in Python we have seen now to create the user defined funds and with the Dave cured and giving the
name but the end only must funds and doesn't have any name.
That is the beauty of the anonymous funds and let's see how this anonymous function can be created.
So anonymous funds and have returned types.
So something like double.
So I'm just saying w will be written and if you want to make you use up the anonymous funds and it should
be with this cure lambda nonsense.
So it is also called sometimes the lambda for instance because we make use of this lambda keyword so
after that lambda make use of the argument that you want to pass and the value.
So let me say X multiplied by two.
And I want to print the double of five let me say dollar five.
It is going to give us obviously 10 value.
So this also funds and so what we just did here was let me just define our normal functions.
So I am this day someone doing something like X and printing me yucks multiplied by 2 and calling that
once and wi fi value in it.
So if you do Sam me to just give us 10 and 10.
So this is done by the lambda fund since all the anonymous functions and this is our normal user defined
function.
So here we can see this alumni keyword contains an expression which is this expression and argument.
So this argument can be any number of argument.
It can be one argument or argument.
You can simply pass y over here zero over here but this expression which is the X multiplied by two
it should be only single.
So you can't simply pass here something like Y multiplied by eight again.
This is not valid.
It should be only one time you can do something like The X multiplied by Y multiplied y z.
This is valid.
So you can simply pass here in the double 5 8 and 9.
You can save this place of five.
You'll get the value but the expression should be only one.
This is only valid if it was Bossier something the expression 2 3 expression you don't do valid.
So this is the lambda functions we have to explore more of this in the upcoming lecture we'll see the
packing and unpacking the arguments skewered arguments in the upcoming lecture but for now we have seen
how to work with the functions how to create our own fun since we have been using the couple of fun
since in the earlier lectures like playing defense on and drains funds on and input funds and but for
now we have seen how to create our own functions and just executed by our own way.
See you in the next one.