Now, let us go ahead and deep dive into the building blocks of objects and the classes, so we have
seen a small example how we can work with groups and how is it really helpful.
But now we will actually create stuff and start with the very basics.
So the first thing which we will be learning about is objects now in Python.
Everything is an object.
So from the previous lectures, we used to have a type function that used to tell us the type of object
or anything.
OK, so let us have a look at this.
OK, so let me print
and I'll bring the type of something.
OK, so let me copy this and paste this again and again for several times.
OK, now first of all, let us see the type of C one.
Let's see the type of full list.
Let's see the type of O double, let's see a type of dictionary.
So you know that this is for a list.
This is for a double.
This is for a dictionary.
So let's run this note so you can see it shows me a class in class list, class double class dictionary.
So what you get to understand from this is that all of these things are objects and how can we create
an object?
We can create object with the use of a key word, which is class.
So to create an object, be forced upon me to create the class.
So unless and until we have a class, we cannot create an object.
So let's go ahead and have a look at how we can create a class.
OK, now what is a class now?
Class
is an user defined object are created using the class keyword.
So unless and until I have this class keyword, I cannot create the object.
So the class is basically a blueprint that defines the nature of a future object.
So if I want to create an object, I will have to define a blueprint or template from which the object
will be created.
OK, so here what we did, we created a blueprint of a person and using this blueprint, we created
several forces, several objects of the person.
Right.
So we can do the same thing here.
Now
what is an instance?
OK, now from classes we can construct different instances.
So when I say Nezha going of Camonte, these are different objects.
What are objects?
Objects are the instances of the class.
That is something the instance would you create from the blueprint.
That is the object which we create from the blueprint is the instance of the class and an instance is
a specific object which is created from a particular class.
So when I see here Munsie instead of Morante, I would have given say or do one object to.
OK, so this is a person like this, so this object one would have been the object.
So this object is nothing but the instance of this person class.
I'm this person class can have several.
Object, it can have several instances.
OK, now let's go further.
So we have created a list here.
We have created this list and from this list, we can create different object.
So now let us go further and create a very simple object.
OK, so how do we create that?
So I say class.
This is the key which we use.
After this, I provide the name of the class.
So let's say my class name is something and this is the class name.
And I simply say, OK, this is the syntax of it.
Now, further, I will have to give something which is related to the class.
Now I will have to provide certain I prebuilt or Dimitriades in the class.
OK, how do we give that.
We'll see that later.
But for now we will simply say, Busse, this will just deal with whatever we are doing and see how
we create the methods, all the attributes later.
But this is the very basic syntax offered we go for.
Now this is my class.
Now how do I create an object?
I create an object by saying, let's say X equal to something.
So now X is the object of my class sample.
As simple as that, you just give the name of the object and you assign it with the class itself.
OK, now if I want to print the type, I can simply say print.
And I would say that if I didn't say this, I'll give X..
So now you can see that X is nothing but the object of the class stamp.
OK, so X is the object of the class.
Now, by convention we give the classes a name that starts with a capital letter.
That is why I have given this as a capital is Hiroto.
I have given it as a capital B for the person.
OK, now how X is now the difference to one new instance.
So whenever we are creating this sample, so X is the new reference.
So whenever I want to find out or run so certain properties or get to know about different properties
of the instance, right now this is creating an instance.
When I see a sample it is creating an instance, but I need a variable which will actually refer to
that instance.
It is something like you have created a placeholder X, which contains the instance of the object class.
So this is the object.
So X contains the object.
Now, whenever you want to refer to anything inside that, you will simply say X dot and you will put
the attribute or the method name.
So if I have attributes Egilsay extorted, if I have an attribute start name, I will take extort name.
Now, if I have any method which I have defined, then I will have to seize the let's say, eat so egg
start to eat.
And to run this I have to give it with abrasives.
OK, so this is how we like this.
Now here we have instantiated the sample class.
When we did this, we have instantiated the sample class.
Now inside of the class, we currently just have this bus.
OK, we don't have any methods.
We don't have any attributes.
We had methods and attributes here, but we don't still don't know how to write that.
So let's get a photo now, we can define these methods are not revealed so we can let you create a class.
OK, now for that class, any characteristic of an object is called an attribute.
So when you look at this particular class, this person has a few characteristics.
So what are those characteristics?
The name age rule.
So these are different characteristics of the person.
OK, these are called attributes.
Apart from that, we have methods.
Now, what are method methods in operation which we can perform on the object?
So this create person display person E to walk, talk, whatever the person can do is called the method.
OK, so now what we will be doing is we will be creating a class called Dog, OK, and we will create
certain attributes of that dog.
Let's say it's a breed or its name.
And apart from that, we will give certain methods of the dog, which would be, let's say, barking.
So Adolphine bark so we can create something like that.
OK, so let us create that and then we are creating that.
So when we are talking about this, so we will have to create attributes.
Now when we are creating attributes, we will use a self operate on this soil.
For Breteau means when we are writing self something, this means that this object dopp the characteristic.
So whatever object I'm creating, so if I have creating object one, then the particular characteristics
characteristic which is associated with this object is referred to by self-taught means or self.
So when I say sell dot something, it means that I am referring to something which is specific to that
particular class for specific to that particular object.
So I can have two hundred people or three hundred people or thousands of people.
So for each and every person there will be a different name, different age, different groups.
And how do I refer to that?
I refer to that using the object, dog name, object, dot age, object or drooly.
Let's see how we can do that.
So the first thing which we will be doing is we will create a class.
So we have created a class and we see dog.
So this is our class dog.
And previously what we have done is we simply said, boss, so this simply created the dog class.
Now what we can do is we can create the function.
Now there is a specific method.
Whatever functions are present inside a class, they are called a method.
So the first method which we have in any class is the init method.
OK, how do we define that?
We will see this double underscored it double in the school and it will be set by default.
This is something which you will be providing it every time when you are writing this in a method.
OK, and this init method, what will it do is when you are creating an object out of this class, this
function will run by default.
So when we saw these two functions create person and display person, we have to run these.
When we created person, these did not run.
We had to run these separately.
We are to run these separately.
But now when we are creating this đinđić, this init method will run on its own as soon as you create
an instance of this class.
OK, so let's run this and I'll simply print and I'll say dog created.
OK, dog object created.
OK, yes, I have created this sum and on these I do object.
So when I run this what each objected to sink object created.
Object created.
So this I have done for this particular class.
Now let's say I want to provide some attribute to it.
OK, now what is my attribute.
I want to put in that, I want to give the brain also along with.
So Sabri Anayansi says dog breed is equal to breed now this breed is nothing but this one and this breed
is the attribute, OK?
This is the attribute I could have given any other variable also.
But this is the simplest way of doing it without creating any confusion if you're using the same name
here.
This will actually avoid confusion, I think would have created something else.
Also, I'd say breed and insiders.
I can say eggs and I can put eggs and say this doesn't make a difference, but I'm reediting breed here
for simplicity.
OK, now this breed has been created.
Now I will simply run this.
So when I create some dog object, I have to provide this breed because it will be needing it.
So if I run it this way, it will give me a letter saying missing one required position.
Like many breeders, it is expecting me to provide a breed.
So I will simply say lamb.
And here I say, let's see, Husky.
OK, so these are the two breeds which I have and I found this so you can see Dog Love and a husky has
been created.
Now, apart from this, what you can do is you can also bring the details and everything.
So for granted the detail again, you can see the whole object has been created and the breed is comma.
So dog breed.
So wherever you will be using this attribute, right.
You will be using it using the self phone.
So wherever I want to use the attribute, I will see a self-portrait.
This will only mean that I want to use the breed which is associated with my object.
So I run this again so you can see that it is giving the breed.
So I have created two different objects on these objects.
Have the relevant details about this.
Now I can also do something like after this.
I can also see I'm not a breed, so this will give me the details.
So it's saying it is lab.
It is saying don't breed is Huskie, so it will give me the details accordingly.
If I put print here then it'll show.
So this is what we do.
Now let's break down everything.
So the special method in it is present here.
This each attribute in a class definition begins with a reference to the instance object.
OK, so everything will begin with the.
Object of the.
Plus, now it is by convention himself.
So this is my convention given I said, OK, now here we have the breed, this breed is nothing but
the argument which is giving, which we are giving inside this.
So by going by convention, we are using in this way and we are putting greed inside.
This was simply simplicity.
OK, now the value which is parsed during the class and instantiation is this breed values.
We are passing this here.
That is very it is taking the value in the IT by default.
I'm saving it inside this breed and running this so this init method will run by default.
We don't have to do anything to run this separately if we create any other method.
So to run that method, I have to run it separately.
So if let's say I do something like this printer and I just put it like this and I say, print, hi,
I'm pregnant, OK, so if I do it this way, so I won't get anything out of it because I am not running
this.
So to run this I'll have to see, see some dog print.
OK then only drylands.
See it is printing it now again if I want to refer to the breed I'll have to see selectivity.
I just simply give it so it's not taking it because we have not used the self operator because it is
not defined.
So I have to give, said Dr..
Breed them.
OK, now we have created two instances of the dog, Lansdorp is some unknown, OK?
And they do have two different breed.
OK, and these are the attributes which can be accessed using Dornberg green and some don't breed.
OK, next.
Now, we don't have any bad instances of the breed.
OK, if you see Prenter has opened, this is up by breed, does not have a parenthesis after.
OK, now these glass object attributes are the same for any instance of the class.
OK, so we could create the attribute species of the for the dog.
OK, now the dog's regardless of their breed, name or other attribute will always be mammals.
OK, so we apply this logic in this particular manner.
So we just apply this particular logic that if let's say we have something which is common to all those
attributes or for all the objects of this class.
So how will we do that so far that what we can simply do is we can provide something like, OK, so
all the attributes will be provided inside the functions and the common ones.
That is something the ladybirds or any other words which are common to all the.
Objects of the class will be provided outside, OK?
I can use a display and I can see the to be fuelcell so I can get the species for Don, because mammal
is common for all.
So I can see it for all of these.
The next thing which we will all learn about is methods.
So we will look that in the next session.