As many other programming languages, Python is also a very good object, orientation, language and
what means object orientation.
This means that also Python can create a custom class.
So we already learned the most famous data types or the most famous classes disordered, the integer
string.
William and so on, OK, in this class are predefined, but sometimes you want to create a type that
is a custom one and really simplify so called.
For example, if you want to create.
Different types of animals.
It is way easier to have a pretty defined class which implements all the methods that are applicable
for exactly animals and all the different colors and breeds and basically different types of animals
that you can find out there.
And this is quite useful when used in programming.
And to be honest, most of the complex and real world codes are object oriented.
But let's see how this works now in our IDE.
So you declare a class by keyword class in Python, so separate class then the name of the class.
In our case, animal is the class who can go out the functions applicable from this class.
For example, what an animal can do.
Well, the animal control.
So I will create a method so def.
Run in then self, and now let's print what is going to happen, and just so here, we're right running.
So when we call this metal for an animal, dismiss the animals running, no, let's create another method.
So T.F. eat and then print eating.
Right.
So this a class of animals and, you know, all the animals can run and eat.
And for that reason, disconcert implemented here.
But now you're creating an animal that have this features or how you're creating an instance of the
class.
It is very simple.
For example, I want to create a dog, so dog will be equal to animal.
OK, this is the same way a certain variable can be integer.
For example, on no, let's say from one to 10, the numbers from 149 in are integers.
Right.
And the dog is of a type animal that's already defined.
So if I write Dog Dot and you can see now when they write the dog dot, they're in the Middle East and
were unavailable because they're available for this class.
Right.
So let's choose the Middle East and just from the cold.
So if I run it, you can see that the dog is sitting at the moment, right.
Now, you can also at some future with this dog.
So if I write a dog Dot.
And then the British will be Podell, OK, and I what all of adult.
Age in the age of the dog could be five years right now if I were to print Dog Dot.
H I will get five for the age of the doc, OK, but do you see something that is not quite right here?
Well, the problem here is that every time that we create a dog outside of this class, we will need
to define dog, dog, breed.
So we are defining a new parameter and then saying that's a poodle or dog to teach in stating that it's
five years old, isn't that better?
If we could have this features inside our class and yes, in Python, you can do that.
And actually the most useful way to do this is by a constructor.
And what constructor is?
Well, it just means that basically when you want to create a dog or any other animal, when you want
to create an animal, you definitely need some parameters that are going to be assigned to this animal.
For example, D.F. and constructor is marked by init or just the initialization.
OK, self cómo.
Breeds.
Colma color.
And then the cycle itself not breeds equal to greed and self-doubt.
Color is equal to color.
OK, so now every user that wants to create an animal first has to declare what is the breed in the
color of this animal?
OK.
So now the creation of the dog will look like this dog equals animal, so class animal inside the briquettes,
it's right for them in the car will be white.
And now if I want to print dot, dot, you're getting great, Cowwarr, I'd run and also dismantlers
here.
So if I would like dog breeds and let's actually add it in the print statement.
So if I run the code now, you can see that we're getting the breed of the dog that was defined once
we declared our dog.
Right.