OK guys.
Welcome back to another class of course about Python.
Until now we saw many many very interesting things about Python.
How it works how to programming this language and all this kind of stuff.
And today we are going to talk about a very important part of python.
This will be about classes and objects.
What exactly are those.
How would they work.
And what exactly can do with classes and objects.
So basically those two things are used in many many programming languages.
And this is why they are very important.
This class may be a bit hard.
So if you don't understand don't hesitate to see it again and again just to get the point of what it
is exactly.
All right so let's start.
So basically what are classes in Python.
Classes are let's say a set of data that will help you create basically and another type of data that
is more personalized.
So let me explain.
Let's say for example you have a pizza.
So the pizza in itself could be a class.
So why.
Because while the pizza could be a class anything could be a class.
So let's say that you take the pizza so that the pizza class will have attributes those attributes will
be for example the price the size and the pizza type.
So let's say vegetarian if you're only cheese whatever type you want the price.
And as I said the sites.
So those three attributes will constitute a pizza.
You can add as many attributes as you as you want.
It doesn't really matter but just for you guys to understand that a class is simply a let's say a set
of data that will create a personalized data.
So in this case as I explain you will give attributes to let's say you will create a pizza so you'll
create a pizza as a whole as a whole.
So an object on the other hand is simply the same pizza.
But this time personalized let's say I'm buying a vegetarian pizza for five ninety nine.
So this will be my object.
So that vegetarian pizza the small vegetarian pizza that costs five ninety nine for example is the object
the class is the pizza as a whole.
And all the attributes that come with the pizza.
All right.
So I know that you understand all this will create our first class which will be once again the pizza.
And you guys will understand a bit how it works and what exactly can do it.
So degree the class.
First of all you need to create another bite on file.
So simply go here go on you and simply open up python file.
So click on python file and you can name your file pizza I name it personally pizza.
All right.
When it's all done you can simply go on your file which is pizza and create our class.
So the way we create we start the class creation is very simple.
I simply write down class.
So from here we have our class we will name it pizza one.
So let's make it as I said pizza one.
All right.
So right now right here as you can see you have your class which is pizza one from here.
You can define what you can.
You need to create a function.
So in this case we'll write down that and then we'll use a class creator.
So in this case we'll use the the method E.A..
It's a special method.
It's which is called class constructor and this will help you.
Well this will help you.
This will simply create your class.
So very simple.
You may simply come a bit down here.
So you go in there and you write down E.A..
So be a..
It will appear as you can see it's there.
You simply click on it.
And from here you need to create all your attributes.
So in this case our attributes will be the type the price and the size.
So we'll have only two attributes we tried to make something that is very very simple.
Next thing that you guys want to do is simply write down self.
So in this case we'll call each attribute.
So type and we'll be equal to tech.
So very simple.
Simply write down self that the name of your attribute will be equal to the name of your attribute to
be able to call it in your project right here.
So after that we'll call each of those attributes in our project.
So you do the exact same thing for each and every class.
So we have our price will be equal to price.
And finally the size will be equal to size.
Great.
So we have everything that we need.
The next thing that we want to do is very simple right now that we have our class.
We want to create our our first object.
So how exactly do we create an object in Python.
Very simple.
We come back in our project right here and we create our first project.
So the first thing that we want to do is we want to import our class right here.
So what exactly will import.
So will start right this right down from.
So from where we want to import our class.
We want to import our class from this sheet.
This sheet is named beads.
So we want to import pizza
from Pizza sorry when it imported from pizza.
And what we want to import from pizza we want to import the class that is named pizza one.
So we want to import pizza one from pizza.
I know it's a bit complicated because different names are the same.
But at the end of the day you get that.
You want to import pizza from Pizza one.
All right.
So the next thing that we want to do is simply create our.
Well our our object.
So very simple our object let's say it's gonna be pizza V which stands for a vegetarian pizza and our
object will be equal to pizza one.
So once again we are calling our class so pizza one we open up our apprentices and we write down what
exactly will be in our Pete zone so in this case what exactly will be in our piece I want.
We will have the type of the pizzas in this case it's gonna be a vegetarian pizza.
So vegetarian we will have the price.
So in this case it's gonna be five dollars and the size in this case we want it to be small.
Great.
So we have our attributes.
So this is our object an object looks simple like this as you can see it's it's like a variable the
way you create it.
It's simply you write down your object or your object here.
Write down equal equal to the class and all the attributes of the class.
In this case all the attributes are here so the type the price and the size when it's all done you can
print each of those attributes so let's say you want to print what exactly want to print.
We want to print our object pizza V.
So we call it pizza V.
And what exactly want to print in our pizza.
Very simple we want to print let's say the size.
So size.
Here we go we have our size.
So if we run our up as you can see the sizes printed and the size is small let's say you want to have
another object right here.
So let's say I want to create another object which will be pizza B which will stand for pepperoni pizza.
So once again we created the same we write down pizza.
So the name of our class which has been the one we open up our parentheses and we enter all the attributes
that we want to enter.
So let's say in this case we want to enter.
Well we want to write down which let's say when I write down pepperoni.
Then the price will be ten dollars and the size will be let's say large.
So if we do the same thing instead of pizza we write down pizza.
And we run up you'll see it's gonna give us the size of pizza P which in this case is large.
I mean just fix it.
Here we go.
So as you can see we have large as an answer so it's not very hard to understand.
The only thing that you guys have to get is that you need.
Well you need to create three class at first your class will be a set of attributes you can enter how
whatever whatever attributes you want that.
And they're here from that point when you have all your attributes you can create your object because
as I explain the class is simply the whole product.
So the whole pizza will be the class with all its attributes and the object will be the specified pizza
so the pizza with all the specified attributes so let's say you will have the size of the pizza the
large vegetarian pizza that costs five dollars will be the let's say the the output.
So it would be the object so very simple at first you create the class as we saw.
And finally you create your object can create as many class as you want.
And you can create as many objects per class as you want.
Once again.
So I hope you guys right now understand how everything works.
You can practice it create your own classes and create your own objects as you can see it's not very
hard to understand.
That's it for this class guys and see all our next class.