Hello, everybody, I'm happy that you're here and I'm really proud in each and every one of you that
got up until this point, I can surely say that most of the content of the course is behind us for one
side, from one point of view is a happy thing.
But we should not forget what's coming up next.
So what's waiting for us now is the massive stopping method.
A method is basically a block of code that has a certain headline, and then this block of code can
be executed.
Once we call it OK, it will not be executed by itself, even if it appears in the code we should call
it.
So this will be our next lecture's methods is a very important part in each and every programming language.
And in Python in particular, which is based on OP, you might have heard this term OPIS object oriented
programming, and every professional program in the world knows what these OLP.
And also I'm sure that those of you who want actually to find jobs in programming, you will be surely,
surely you're going to be asked regarding methods and OLP in your interviews.
So that's about this thing.
Additionally, I just want to say that from one hand, the following topics will be a bit challenging
for one side, but from the other side, you should not worry at all, because the thing is that I'm
also I'm always in focus regarding the level of difficulty of the topics.
So these topics would be be challenging.
But from the other hand, I'm going to give you more life coding examples and more perspectives once
we're going over the slides, going to explain everything two or three times.
So don't worry you.
I got your back regarding this part.
All right.
So let's begin what easy method in Python.
So, like I just said, a method is a block of code which only runs when it is called also the method.
You can pass the variables or collections into it from the execution point.
Is it just mentioned there is the method itself declaration.
And then there's a second second thing, which is when you call the method, which is called method
execution.
So in the method execution part there you can pass variables or whatever into the method, then they're
going to be used inside the method.
Sounds a bit tough.
Sounds a bit hard.
Don't worry.
You will see many examples in the following minutes.
All right, an additional advantage of matinées, methods, first of all, methods connected with a
strong connection to the following topic, which is classes and objects, they are connected very much.
And basically what methods gives us it gives us a great power.
It gives us to avoid duplication because you can create a certain code and then you can reuse it.
Or in other words, you can execute it several times by your command whenever you need it.
And you don't need to create the same variables and same loops or whatever.
Again and again.
You can simply just call it whenever you need it.
All right.
So let's go over quickly regarding how methods work and what can it do.
So I'm going to go over the boards and also explain every one of them.
A second name of method is a function.
So whenever you're going to look something, some questions regarding methods in Google or Stack Overflow
or whatever, if you encounter the term function.
So function is method and method.
Its function is the same thing.
Just has two names.
All right.
After a method is created.
OK, so you have Pathé, which is method creation, then you have Babi method call-out or method execution.
So it's different parts in the code.
You have separate lines of code for it.
We'll see it right here in the example in just a minute.
OK, so you first you first created, then you call it and the execution is done in the module level,
meaning it does not happen in the indention under the method and it happens after the methods block
itself outside of the method.
OK, outside of the method, we execute it next.
Both is once the method is executed, all the code inside it will run.
We already know this basic guideline from you, statements and for loops that once, for example, if
we created if statement so everything if the statement is correct.
So all the code under the if statement declaration will run as a whole unit and how the pichon will
know that this code is under the if basically very simple way.
If you have intention for these lines under the if statement, you will know that this is that statement's
content commands.
All right.
By content, I mean it's inside the if OK, because you can best data in the form of variables or collections
into the method from the execution command.
So again, we said we have the execution, we have the creation path and the execution part.
So if you want to pass some variable from the execution part inside the method, you can do it.
You will see shortly an example for this as well in this presentation later on.
OK, and one last thing.
How do we recognize that we are looking in a method once we see it, for example, in loops, though,
the key word for by that we can recognize that we are dealing with a for loop.
But in the methods case, there is this word here def.
And once you see this different key word, you know that ahead of you there is a method from here.
I think it's very convenient for us to see.
First, simple example and let's look at it straight away.
So the first line is method declaration, same as we did with each statement declaration or while loops
declaration.
So this is the the method declaration.
The first key word is that right afterwards we give the name of the method, then we have round brackets
and then we have the two dots special sine.
OK, so this is the declaration.
Then one line behind it.
The second line is the methods, content and by chance would know that this is the method is going to
be hard because you're going to have indention here at this line in every additional line which you
would like to create under your method method.
OK, so this is the method, the content part and right here below.
OK, we went down for a few lines just for this text to fit in.
There's no special reason that there is lots of spaces here just because all my explanations would fit
here.
But we can see here is the method of execution and you can see that there is no intention here regarding
to the method of execution command.
There's no intention like here in the brain, for example.
And basically, only if this path exists, the method will run.
So if you remove the last line and you right.
Click in parts of the file and run it, nothing will happen.
OK, nothing will happen.
So we have to have this last line right here in order for this method to run.
So basically here we call it out, please run.
And then it goes from here from this line goes straight up to the method and goes inside, then runs
whatever is inside the method.
Very simple logic of how methods work.
All right.
Nothing's too complicated in this case.
As you can see, this this this example, it has no best to it, OK?
We don't see here in the brackets some variables that we want to insert into the method and also in
the execution level, we don't see any variables.
So let's see how could we create methods that will contain variables and how can we do it basically?
All right.
So in the previous example, we have seen a method that does not have any did not have any argument
inside it.
All right.
Now, let's have a look on the on one that gets variables inserted into it.
Right.
So basically, right after the methods name, right after def, then methods name and inside the square
brackets, we can put the the arguments or those of you who have difficulty to understand what our arguments,
arguments are basically variables, any type of variables and collections.
And we can put any variables we want inside the method in the execution level and then it will go inside
the method.
We will see here the sketch in a few seconds.
All right.
So in this example, we have the variable age, OK?
And this is what we want to pass.
OK, so let's see this example straight ahead.
We have this one on this example right here, and we can see her death, my function, which is the
which is the method, and inside here, inside the wrong brackets, we can see the variable, which
is age.
All right.
And below it, we can also see print.
The age is casting and also the age goes here.
What the age is not like.
We need to tell this method.
What do we mean?
Age equals two.
OK, we need to tell it.
Age equals to what?
And this can be done in the execution level.
All right, so right here, these three, my function, my function and my function is the execution
level.
And here we can see the concept that I mentioned in the beginning of the lecture that methods can be
are used to get the code to be reusable.
OK, so this method is reusable and it's dynamic.
By dynamic, I mean that you can put any variable you want here and each time you execute, you can
put a different one.
OK, so it's like magic, right?
I really I really excited regarding this topic once I studied it for the first time because you have
the same code and each time you got different variables going inside here, just whatever you want,
you can put inside.
So we go in these two for these two first line we already understand.
Let's talk about the execution level right here.
Also mentioned that you don't have indention here.
All right.
So here.
Same as before.
Same as the previous example right here.
We are calling we're executing the method.
OK, so these three lines are execution of the method.
But we can see up in here that the method needs to get a variable.
And if we don't give it a variable, if we leave the thing here empty, so we're going to get an error
because the method expects to receive something from the execution level right here.
And if you don't pass anything, you will have an error.
OK, so in the first case, I just pass here the number 25 and you can see that this line executes the
method above.
So once I run the the whole file of this code is in the number twenty five goes from the execution level
into the method declaration.
I'll be here and number two and from number two, it goes straight ahead here to the print and the print
gets the variable from the brackets right here.
So this is the flow one, two and three.
Not too tough.
I think even after hearing all the explanations regarding how things work, you can put a variable here.
We can also do not put it variable here, but you need to have consistency, consistency between the
execution level and the method declaration, because if you put here twenty five, for example, but
inside these round brackets is going to stay empty, you're also going to have an error because these
two should be sinked an additional example.
For example, you want to best two variables we have seen in the Bullis that need there needed to be
divided by Colma.
All right.
Not sure.
See it.
OK, right here, you just need to separate them by Colma.
All right, so if he were to variables for example 25 then Colma then we're also going to have an error
because right here at the top of the declaration we have only one variable mentioned here and when we
passing two variables, you will get confused and give us an error.
OK, so we have to, we must have consistency between the execution and the declaration placements.
OK, again, as I already said, each stop, each subtopic here.
I'm going to explain in several point of views.
So those of you who are struggling to understand, let's listen to this part right here.
So the flow, what happens up in here?
Basically, we pass a variable to the method from the execution placement right here, number one.
Twenty five here.
We add the number with our keyboards and we choose whatever we want.
All right, that variable will pass and we shall use it inside the method.
OK, so this variable will be used inside the method in number three here.
Then the value is accepted in the method of the operation.
So we send it from here.
It's received here.
And the method declaration inside.
Number two, here it is received.
And from there the variable is used to being called.
The variable is used to where it is being called inside the method.
In our case, we have the print actually print action here, the print command.
And here we're using the each variable.
I think that's about it.
I think it's enough for the introduction and it's enough for it's not really an introduction.
It's more than that.
It's enough for the very easy to understand how they work, how do we recognize them, what are the
characteristics and what are the benefits of methods, methods without variable and method with variable.
So we cover this whole thing up.
And I guess that you will see some live code examples in the next video to understand it better.
OK, so we're done with this one.
I'll show you the next video and thank you.