Hello everybody and welcome back to Python basics tutorials.
Now we covered functions in the previous video.
We also cover some of the loops while loops if loops for statements and all of that.
We covered some of the Python basic such as variables and we also covered some of the most basic programs
that you can write with python.
But right now what we want to do is actually show you another thing that is in Python.
Since python is project these object oriented languages many of the code in for example big parts of
codes are oriented in these classes.
Now classes are used in order to keep some of the related things together.
I'll show you the most simple version of classes so you can actually get a brief understanding of what
they actually are.
So let us get right into it.
So let's open up our part on an interpreter.
And in order to actually set a class you just use the name class and then the name of the class itself.
So the name of the class or Let's type your class person you specify the open brackets and then you
specify two dots in that.
So after that you need to specify everything in this class.
So basically most of the classes will have something called self.
Now it might be a little bit hard for you to understand that but you will need or you won't need but
it is most likely going to you are most likely going to start the classes with the function called in
it.
Basically what this means is it will give all of the objects that are currently corresponded to this
person class.
So for now on lets us add the self object and the name object the name basically something is basically
a name that this person will have and the s object is the object that we are going to refer to in the
class.
So let me explain it to a little bit better to you know so you can understand it basically well this
will do is if I just type yourself not name equals name.
This will put ourselves that name our name variable in self-taught name variable.
Now this is something that you will see a lot in these classes.
This is basically just the syntax for the python so you will need to get used to it.
If I just type here enter you will see the thread.
Now we have the class Person identified and we have it right here in Python interpreter in order for
you to use this class person.
Basically what you need to do is actually just type here the name or any variable so Person 1 or let's
call it.
Oh yeah let's call it Person 1 which is a variable equals and then we need to put the class that we
want to put this person in.
So class Person 1 We want to put him or her in the Person class and you can just type your person and
presenter you will need to specify all the arguments that we specified in our class which in our case
is only the name.
So what we need to specify is the name so let's call him John.
So under the quotes you just type your John and you can press here enter.
So now we have a person one which is stored under the class person.
So if you wanted to just type your person one you would see OK this is a memory object.
So let me just show you it like this so print in order to print the person's name you will need to print
person 1 which is our John and then dot and then we use the object we created in our class which is
the name.
So that is the only thing that we have in that class or print person that name and it will give you
the John.
So if you just type your person not print not prison but person to person.
Now let's add that to the class as well and let's call her Jane.
So person Jane and print person to not name we would get the name Jane and now both of these variables
correspond to our correspondent to this class that we created.
So that's what they mean by keeping the related stuff together with classes.
Now this is the most simple use of it.
Basically in this one we only had the variable name which we gave to our objects or basically to our
variables Person 1 and Person 2.
You can have multiple things.
So let's see what we can do but let's close this interpreters since it's better to code our real program
so Nan or Python 6 by and we start off with the usual things so fast to the python.
And right now let's create the class which will store our name of a certain person and which will also
store an email of that person.
So that will be pretty similar to what we did in the previous thing but we also need to specify an email
in our class.
So let's call the class for example
information.
Let's call it like that doesn't even matter.
And what we want to specify right there we want to specify or we actually want to leave it closed so
don't type anything just type your two dots after the brackets and then presenter and we create the
simple function as before.
So the F def in its function we put the self right here and we put the name and email since that is
what we want to actually have for every person we put in this class what you want to do right after
that we want to do the same thing that we did before so self not name equals name self self-doubt the
email equals e-mail.
This will store both name and email in our class and right now all we have to do is basically just give
or create a variable which will be corresponded to a person and put it in this class while also obtaining
the name and the email for that person.
So let's do that runs through right here.
So let's call him Jack or let's call him.
All right we can call him Jack equals and then we want to put him in a class we put that with just specifying
the name of our class which is information which is probably not that good of a name for this class
but it doesn't matter currently and we open brackets right here and what we want to do is just specify
these two things.
So the first thing would be name as we specified firstly.
And the second thing would be email.
So right now we open quotes first of all we specify Jack as a name.
We put comma right here and then we specify the email so let's say it's Jack at gmail dot com.
And that would be about it for the specification of the jack for this class.
So all we have to do right now is if we want to print the information for Jack.
You can just type your print Jack dot name and print Jack dot email.
So that's how you can use this.
Basically it is really simple though everyone seems to understand this.
The hardest.
I did too.
But once you actually get used to this you will be this one really present that much of a problem to
you.
Classes can be a little bit tricky sometimes but they're not that hard to learn.
So you just save this control or to save can enter and the control X to exit.
Right now let's see page more dollar by six and run it six slips.
And here we can see that when it prints out the name and email we get the jack and jack at gmail dot
com.
So that will be everything for classes.
Now you can also stack classes one under another so class in a class in a class in a class.
But that is the more advanced section basically.
We won't be doing that right now.
And we also don't need it for our coding or backdoor.
So there is really no point in doing that.
You can also use certain parts of the class in a print statement so let me just show you so you can
see so you can just type your print the user's name is and then you just type here.
The closed quotes and then plus and then jacked up name so you can do it like that.
It doesn't really matter.
So the plus we'll just add the string of this to the string right here that is specified.
So this will specify the user's name is Jack.
You can do the same here as well so the user's email is and then plus the string.
So we say this once again.
And if we run it you will see the user's name is Jack and the user's email is Jack at gmail dot com.
So that is probably something else you didn't know which is that you can stack two strings together.
So this is one string which is just the name which in our case is Jack.
And this is the second string so it will just add the string to the end of this one and it will print
out the string as a single string.
So that's something useful to know.
So that will be about it for this tutorial and in the next one I will show you how you can actually
import libraries from the Python and also import your own libraries which is also useful and which is
something that we will do in order to create our programs.
Basically it's you would be having to type all of the things from the very beginning if you don't include
any libraries.
But luckily we have some of the libraries that other people coded for us that we can use in our own
programs with just a little bit of effort.
So that would be about it for this video.
I hope you enjoyed it and I hope I see you in the next one.
But.