Hi, everybody.
I'm so happy that you're here with me, and today we're going to discuss further regarding object oriented
programming in Python.
In the previous video, we have seen an overview of what is an object and how can we create instances
of an object.
We had like a sketch of a car.
And on top of that, we could create two types.
Of course, this was only an overview look.
And today we will start explaining each term before getting to the point where we can create actual
objects like advanced objects.
We will start explaining everything from zero from this lecture right now.
And let's go over the list of terms that we are going to discuss in this lecture and also in the following
lectures as well.
So what's in our menu?
What is a class and how to create one?
We will discuss it in a few seconds right here below how to create an actual object.
And then we'll learn what our properties of an object we will use a special method and also a special
type of method that we haven't seen before called in it.
OK, so look down to this thing as well and then we will talk.
What is a self parameter of a property?
These two are connected.
Don't worry if it sounds a bit scary because as you know, you don't need any prior knowledge.
Do all this.
We're going to discuss it from zero.
OK, and then we will learn what our object methods and how to use them.
OK, also, after we'll explain all of these terms, we'll start building the car object that we have
seen in previous lecture from zero in live coding examples as always.
All right, so first of all, let's start with the third with the first bullet classes, OK, so what
are classis?
So we are all very familiar of how to declaring method's OK.
So once we want to declare a method, we just use the Def Keywood and then afterwards we put the name
of the method.
Small letters underscores between each each word as the coding convention tells us.
OK, so a class declaration happening in the very similar way, but this time we will have to use a
Klasky word and then give the name of the class.
All right.
So this is how we create classes, but where classes fit in, in the hierarchy of PyCon, meaning,
for example, we know that our methods.
All right.
And we can contain variables inside these methods and we can also manipulate variables inside these
methods.
But we know that a variable is inside a method.
OK, so method contains a variable.
It can contain a variable.
But where classes come in all this picture.
So let's go over the whole hierarchy of all entities and see who is the parent of who.
It's very, very simple.
All right.
So first of all, here in the bottom left, we have in the screenshot we have a file called Filed by.
OK, so the file of Python called a module.
This is the official name of a file entity.
It's called a module.
OK, and then beneath it, OK, beneath it.
Meaning in the hierarchy, inside inside this file, you can see here at the top as the first hierarchy
inside a module is a class.
OK, you can see here the class keyword colored in orange and then you can see this is my class.
OK, this is the name of the class.
And then to come afterwards, we will also discuss naming conventions between classes.
You can see it's not written with small letters and the scores.
All right.
We'll talk about it in a few minutes.
But the fact that I want you to notice here that class is the top hierarchy.
Then you have some indention and you have a method.
OK, and then you have some more indention and you have this.
This is my variable equals five.
OK, so class either is the parent of a method and method is the parent of a variable.
This is how it works.
Right.
And just have a quick reminder regarding coding conventions.
We always discuss that.
I want you to become a professional developers and not rookies.
And for that, each professional developer which will look at your code, you'd notice if you a pro
or not, simply by the naming of your entities inside your code.
So I have to mention that classes goes with capital letters in all of the words and without underscores
between the words.
So you can see an example.
This is my class right here.
So this is the coding in the naming coding convention for Python classes.
This is the official way to call classes.
OK, so concluding the whole this whole session, we have a file which called a module, and then you
have a class that is the top hierarchy inside a module and beneath it you have the method and then you
have a variable.
All right.
Let's go further down the road.
OK, so now we already seen here a creation of class, by the way.
You even you haven't even noticed.
OK, but now let's see how to create a class.
What are the rules?
What are the simple basic rules?
OK, so let's look at this part.
OK, so you create a class, use the keyword class.
Obviously, we just talked about it.
And let's see, how can we do classes declaration.
OK.
So once you want to declare a class, just write the class keyword and then write the name of your class
with capital letters with no underscores between the letters and then put to dots afterwards.
OK, so this is classic Liberacion.
Then in this specific example you can see a variable is stored straight away under a class without any
method inside this class at all.
OK, and this is not a problem because here you can see the class is there like Grant.
OK, you have two generations here.
Class is the grandparent of these variable meaning class is on top of variable.
So once we are not having this method here, it's OK.
So a variable can be stored.
Class is this is not a problem.
OK, and you have a simple variable here, you equals two thousand.
This is a simple variable and set a class and that we have just a simple PERENT action, by the way.
It's an error because it's not an ear, actually, it's a car owner.
Just fix it like that.
All right.
So we have here a class declaration, we have a class name, we have a variable and we have a simple
print of that variable.
All right, so there you go.
We have created a simple class, not very difficult, nothing to worry about, you see, just declaration
and then you can put stuff inside it for now.
All right.
So now we can use the class of car class, this class, and let's create an instance of an object or
an instance of a class also.
All right.
So we have this class and we want to create an instance for it.
So this is like the old car sketch from the previous lecture where we've seen, like, a simple old
geraud car.
OK, so this is it.
And now we want to create an instances out of it.
OK, so this is how you do it.
All right.
So here is the class declaration, as we have seen a few few moments ago, right here below, you can
see an instance of an object.
OK, so at the left part, just right the name of your instance, you can give it any name, same as
a variable.
Just give any name, small letters with underscores.
OK, it's a variable.
Then you put equals and then you put the name of the class that this instance belongs to.
OK, the Audi underscore a three instance belongs to this car class.
So just write the name of the class.
OK, so we have now an Audi A3, which is an instance of car class, and we also have a Ford Focus,
which is a second instance of an object or instance of a class.
And it also equals two cars class meaning.
Meaning you can imagine that you have an arrow, an arrow going from Ford Focus, going to car class,
then going on top and going inside car class.
OK, and also from all the three Audi A3 goes an arrow to car class and then goes straight inside car
class.
OK, so both both of these instances belong to car class and therefore they're called an instance of
an object or an instance of a class.
OK, there are several names for these instances.
All right.
This entity called an instance, you have several names for them, for it.
And they're basically mean, the same instance of an object object instance or instance.
You can find all of these names and stack overflow or in articles that you read on line.
So each developer calls them differently, but it means the same thing.
So this is basically what we have here, a declaration, which is the top part.
And we have two instances of an object.
OK, this is the first instance, Audi A3, this is this is the second instance, Ford Focus.
And they're both belong to the car class.
They're both instances of the car class.
Um, I think this concludes the first part of classes.
Let's discuss some more of these topics in the next lecture.
I actually think that in the next lecture we will discuss what our properties of an object and what
is a self parameter and also how to use object methods.
All right.
I think this is it for today.
And I will see you in the next lecture.
Thank you.