Hello, everybody, and welcome to the Methods Advanced Lecture.
Before we begin, let's have a quick overview regarding the topics that we have covered in previous
lectures.
OK, we started off methods, basics, where we were, where we encountered basics, theory, terminology
of what our methods and what they are capable of right after we have seen several examples.
The first example was a simple method declaration and also method execution right here straightaway.
Afterwards, we have seen that we can pass arguments inside and method.
Basically, we have set a number of variable right here.
And also we have seen that data flow that that goes from the execution and goes to the declaration and
inside the methods content right here.
OK, then we passed all.
We passed on to the mid-level lecturer's of methods.
And here we have seen some more cool tricks.
We have seen that we can use default values inside methods.
And in cases that we are not having input inside it, we will not have an error or we will avoid an
error or an exception by putting a default value right here.
And then we have studied also the methods can receive variables from the other hand, also can return
variables, and this return value can be used outside of the method in our purposes.
Whatever we want, we can even pass it on to a different method as well.
And we have covered this one as well.
OK, so I think that now we're ready to go for work forward to methods advanced.
And before we begin, just want to have a few words.
OK, so as in the advanced lecture would be a bit more challenging and especially the methods just preparing
you that you will see some examples and some theory here that is a bit more challenging.
But worry not because I have backup for you as well.
I'm going to show you live examples regarding each of these examples, which is going to executed on
PI charm.
So everything's going to be just fine.
And also, just a quick tip for life.
Each time I have a big problem, I always break it down into small pieces.
Let's say, for example, like a young man is thinking, how am I going to bring my life together?
I need to have a wife.
I need to have a car.
Do they have a job, a house?
And all these seems really threatening at the beginning.
But then once he starts to breaking it down to small pieces, for example, I need to study I need to
study a certain field and then find a job according to this field, and then to go and meet some people
and then meet a girl and so on and so on.
So once you have a plan, nothing is threatening and everything is just turns to be easy.
Right.
So this is exactly the type of studying that I believe in, and I think that will be just fine.
All right.
So let's begin.
All right.
So first of all, we have seen in previous lectures, let me just fix the sentence.
In previous lectures, we have seen simple examples.
Of methods and some foundational features of it.
OK, and we can also encounter a keyword arguments, which we just talked about briefly in the in the
first lecture right here.
OK, so we have seen that we can pass arguments.
Arguments are basically variables or collections of data, basically called arguments.
OK, so we know that the arguments are variables and collections, but what are basically keyword arguments?
We already know what it is like.
It's the term which is not familiar to us.
Let's see what it is.
OK, so basically we can pass keyword arguments and the keyword arguments are like variables, but this
time the variables are not coming in the form of a single string or a single number.
The common syntax of a key value.
OK, and where we do, we are familiar with the key value syntax, obviously, from Dictionary Stoppie,
correct?
Yeah.
OK, so let's see a quick example here of what's going on and how should we handle these keyword arguments.
All right.
So here we have a declaration of a method which we already know how it looks.
OK, form Brandes is our method.
We've said here three variables and pay attention to these variables are mixed in order and there not
by order.
OK, and right here below, we have the execution line where we have a different type of variables passed
into the method.
And you can see that they are like two items inside each cell, which is a key and a value basically
looks very, very like a dictionary.
So brand one key fits for the apple value.
Brand two is Siami and Brantley's L.G..
OK, and then inside we pass all of these variables inside the method and then inside the method.
What we're seeing here is that we're trying to print brand three variable.
Correct.
And once once Python recognizes that we're passing keyword arguments inside it, inside the method,
he knows that once we call out one of these variables, it should print as it should use the value of
the key.
OK, so in our case, once we are passing by three equals L.G. right here and then we call it out.
So the output will show us.
The third brand is L.G..
OK, so it will print out the value of brand three.
OK, so these are this is the logic's.
And I think that we will have much more confidence and we'll just see it inside by chance as well.
And let's try to like sorry, let's try to actually execute this code and see it with our own eyes.
All right, so I've created here some initial some glass for these examples, and once we execute it,
OK, this is the copy paste of the code.
So once we execute it so you can see here, the third brand is LG while here, just copied this line
as well.
We see that it just execute the code and shows us the value of this key here.
This is this is what it shows us the value of brand three.
All right.
Not very hard.
OK, so just one rule here.
Once you pass keyword arguments and then you use it inside the method, the argument.
So the argument will show the value of the key.
That's it.
Plain, simple.
All right, so from here, let's go to the second topic, which are arbitrary arguments and basically
what arbitrary word means is not something which always will be the same occurrence, like random.
So we're not sure we're going to see a method now that we're not sure about.
How many variables should it get on each time it will be executed?
OK, so basically in these examples, we have seen that from the previous election.
Right.
Yeah.
So we have seen here that only one variable can be passed inside.
And for example, if I put two variables here, so we'll have an error because the method is not expecting
to variables.
So now we're going to learn how to overcome this by having arbitrary arguments passed into the method.
OK, so Python gives us an option to have an arbitrary number of arguments when we are dealing with
methods, meaning if you do not know how many arguments, which are variables or collections will be
passed into a method and arbitrary arguments approach is the right one for us.
OK, so let's see the implementation and how do we actually use it?
OK, so you have an example right here.
We have a declaration of of a method of a method here and inside the declaration.
You can see here a special starky, OK, which is basically can be done by shift in the number eight
inside your keyboard.
And once we are adding this special key, the star here, the the method will address this variable
differently from simple variables.
And let's see how exactly.
OK, let's go always to the execution and level to see what we are passing into the method, because
this is the entry gate of the method.
So you can see that we have executed the comp, the clothing company's method two times now.
And in the first time we have passed three variables into it.
But in the second time we passed on two variables.
And you obviously can trust me that this case did not come up with any errors, OK, because this was
intentional.
Once we have tried it with the methods that we studied in the basics lecture, if we will pass you two
variables, it would show us an error or an exception.
And it's a different name for error.
And we cannot continue with our call because it will fail.
OK, but now we're studying that if we're putting a small star icon, small star, our key and then
putting a variable here.
So this would not fail.
You can execute one time with two variables and in a second time with three variables.
OK, and let's go one line inside.
OK, let's go into the content of the method.
And you can see here that I've printed out the the following thing.
The last company is OK plus and then clothing companies and you have square brackets and minus one,
so the minus one inside the square brackets automatically should trigger your brains.
The thing that we have a collection here, OK, because this type of syntax, as we can remember, we
can recall it that this is how we pull out in cell values, out of collections.
Correct.
We studied it.
We covered it a lot.
So this is how we pull our values out of cells.
OK, so this basically means one thing then.
The variable that we have declared up in here is a sort of collection, and this is true.
OK, so once you put here a single star, a key python knows that whatever comes from the execution
line goes here, Open-top here, OK, whatever goes here, this will be turned into a tuple collection.
OK, this is a trick.
You can put two variables.
Three hundred.
It doesn't matter.
Every variable that you put here will be inserted into this clothing companies right here, which will
be a tuple collection.
OK, that way tuple can contain as many elements of the as you want and it does not have any limitation
unless you give it.
All right.
So that that is the reason that inside the Mathas contents right here, if I want to pull out the last
value.
So I'm just using the minus one, and in the first execution, I'm going to have a chat and print it
out and then the second one, the Adidas, OK?
Also, as the previous lecture, did you have some confidence, let me just copy it and put it right
here and let's execute and see what happens.
All right.
There you go.
OK, so first execution, we've inserted one, two, three variables, it went inside the clothing.
Clothing is a tuple, as we just mentioned, and then I asked it to give me the last value off the top.
OK, so in the first case, the last value is and in the second case it is Adidas and it was ran successfully.
OK, but in this case, if I did leave the store, we immediately have unexpected arguments here.
And also if we run, it will fail because, OK, we have only one position.
We have only one argument defined here in the declaration, but we're passing three variables and the
first case.
So we have a we have an execution error.
So this is why this way we're putting a star here and this clothing company becomes a Toppo.
OK, that's about this one.
And let's go straight ahead to the last example, which I believe will be much easier after we have
understood what happened here with arbitrary arguments.
All right, so, Matt, we have seen and this example is that we're passing we were passing variables
we can't pass one, two, three, 10 or 15 arguments inside this method right here.
But now we're going to have an arbitrary keyword arguments.
OK, so keyword arguments we already know, OK?
These are key values, index variables, as we have seen in the first topic of this lecture.
But now the word arbitrary is added to this term right here.
So again, what this means is that we can execute a certain we can execute a certain method without
knowing of how many variables or how many cells it will contain.
OK, so we have used a single star icon inside the previous example of arbitrary arguments, but inside
arbitrary keyword arguments, we're going to use the same technique, but this time we're going to add
two stars in it.
OK, let's see the example so you can see until that keyword arguments best into the method by using
a key value structure.
All right.
Wow.
Just a quick reminder up in here, it became a top all, but we have passed a simple variables without
key value structure.
OK, this is the difference.
OK, so here passing key value arguments that we can pass in this execution, two variables, we can
use an additional execution and best three variables.
And once they get to the declaration level, a python recognizes it will pass key value.
Have here we have two stars.
So he immediately turns this variable right here into a dictionary.
OK, it turns it into a dictionary.
Let's copy it and as well see it and live execution example.
Let's put it right here.
All right.
Let's change the quotation mark, and we should be fine.
All right.
We have some additional or no.
Mike, for us, the indention, right?
Like that.
All right, so that's executed.
OK, so what happened here is that I'm calling because this is a dictionary.
So right here I'm extracting the value of this key, OK?
The Keys model.
And once I mention that the dictionary and inside square brackets state the key, so it should show
me the value you can recall and also cover the material.
If it's not familiar to you, you can cover the dictionaries lectures once again.
But it's the same as we study regarding these dictionaries.
This is how we extract values from a dictionary and that's about it.
OK, so some more of this thing and we're passing here key values, arguments inside the method.
And this time it's arbitrary, meaning I can execute at one time with two cells and in the second time
I can put here, for example.
You're right.
And then put.
Few thousand twenty or two thousand fifteen doesn't matter, and then executed.
And we should not have any errors in the execution, but on the other hand, if we remove these two
stars, you can see here that unexpected oral argument is fast and this is not good for us.
And also, it should not be executed, will be incomplete.
OK.
So I think this covers our three most advanced topics regarding methods.
I also recommend before going to the next lecture off practice to read this material by ourselves again
and try to copy these examples into my charm and to play with it just to change your variables and to
make some manipulations by yourselves, because experimenting is the best starting technique.
OK, so go over the material again and then go to the next lecture where we will start practicing.
Thank you and bye bye.