WEBVTT

00:00.480 --> 00:10.170
Now, let us go ahead and deep dive into the building blocks of objects and the classes, so we have

00:10.170 --> 00:16.880
seen a small example how we can work with groups and how is it really helpful.

00:17.130 --> 00:21.880
But now we will actually create stuff and start with the very basics.

00:22.440 --> 00:28.050
So the first thing which we will be learning about is objects now in Python.

00:28.390 --> 00:30.470
Everything is an object.

00:31.530 --> 00:41.130
So from the previous lectures, we used to have a type function that used to tell us the type of object

00:41.130 --> 00:41.820
or anything.

00:42.120 --> 00:44.650
OK, so let us have a look at this.

00:44.670 --> 00:46.260
OK, so let me print

00:49.410 --> 00:53.760
and I'll bring the type of something.

00:53.830 --> 01:02.070
OK, so let me copy this and paste this again and again for several times.

01:04.710 --> 01:08.520
OK, now first of all, let us see the type of C one.

01:09.400 --> 01:13.740
Let's see the type of full list.

01:13.970 --> 01:23.100
Let's see the type of O double, let's see a type of dictionary.

01:23.400 --> 01:26.550
So you know that this is for a list.

01:26.560 --> 01:29.260
This is for a double.

01:29.280 --> 01:30.450
This is for a dictionary.

01:30.460 --> 01:38.340
So let's run this note so you can see it shows me a class in class list, class double class dictionary.

01:38.800 --> 01:47.790
So what you get to understand from this is that all of these things are objects and how can we create

01:47.790 --> 01:48.500
an object?

01:49.190 --> 01:54.000
We can create object with the use of a key word, which is class.

01:54.270 --> 01:59.630
So to create an object, be forced upon me to create the class.

01:59.940 --> 02:03.890
So unless and until we have a class, we cannot create an object.

02:04.140 --> 02:08.550
So let's go ahead and have a look at how we can create a class.

02:08.790 --> 02:11.280
OK, now what is a class now?

02:11.280 --> 02:12.240
Class

02:15.930 --> 02:22.330
is an user defined object are created using the class keyword.

02:22.360 --> 02:26.580
So unless and until I have this class keyword, I cannot create the object.

02:26.710 --> 02:32.680
So the class is basically a blueprint that defines the nature of a future object.

02:32.940 --> 02:40.050
So if I want to create an object, I will have to define a blueprint or template from which the object

02:40.050 --> 02:40.800
will be created.

02:41.010 --> 02:47.730
OK, so here what we did, we created a blueprint of a person and using this blueprint, we created

02:47.730 --> 02:50.820
several forces, several objects of the person.

02:51.420 --> 02:51.770
Right.

02:51.930 --> 02:53.970
So we can do the same thing here.

02:54.590 --> 02:55.110
Now

02:58.020 --> 02:59.270
what is an instance?

02:59.280 --> 03:03.640
OK, now from classes we can construct different instances.

03:03.660 --> 03:08.660
So when I say Nezha going of Camonte, these are different objects.

03:08.850 --> 03:09.780
What are objects?

03:09.780 --> 03:11.760
Objects are the instances of the class.

03:11.760 --> 03:15.810
That is something the instance would you create from the blueprint.

03:16.050 --> 03:24.930
That is the object which we create from the blueprint is the instance of the class and an instance is

03:24.930 --> 03:28.120
a specific object which is created from a particular class.

03:28.320 --> 03:36.530
So when I see here Munsie instead of Morante, I would have given say or do one object to.

03:37.620 --> 03:46.650
OK, so this is a person like this, so this object one would have been the object.

03:47.700 --> 03:52.380
So this object is nothing but the instance of this person class.

03:52.620 --> 03:55.500
I'm this person class can have several.

03:59.600 --> 04:02.120
Object, it can have several instances.

04:05.660 --> 04:08.010
OK, now let's go further.

04:08.570 --> 04:13.120
So we have created a list here.

04:13.160 --> 04:17.980
We have created this list and from this list, we can create different object.

04:18.260 --> 04:21.900
So now let us go further and create a very simple object.

04:21.920 --> 04:24.030
OK, so how do we create that?

04:24.170 --> 04:25.760
So I say class.

04:26.600 --> 04:28.220
This is the key which we use.

04:28.460 --> 04:30.880
After this, I provide the name of the class.

04:31.040 --> 04:35.360
So let's say my class name is something and this is the class name.

04:35.360 --> 04:40.030
And I simply say, OK, this is the syntax of it.

04:40.370 --> 04:43.980
Now, further, I will have to give something which is related to the class.

04:44.000 --> 04:47.990
Now I will have to provide certain I prebuilt or Dimitriades in the class.

04:48.300 --> 04:49.940
OK, how do we give that.

04:50.180 --> 04:51.290
We'll see that later.

04:51.300 --> 04:57.740
But for now we will simply say, Busse, this will just deal with whatever we are doing and see how

04:57.740 --> 05:00.360
we create the methods, all the attributes later.

05:00.530 --> 05:04.520
But this is the very basic syntax offered we go for.

05:04.850 --> 05:06.180
Now this is my class.

05:07.130 --> 05:08.840
Now how do I create an object?

05:08.850 --> 05:14.360
I create an object by saying, let's say X equal to something.

05:16.070 --> 05:21.640
So now X is the object of my class sample.

05:21.980 --> 05:30.590
As simple as that, you just give the name of the object and you assign it with the class itself.

05:30.860 --> 05:35.120
OK, now if I want to print the type, I can simply say print.

05:35.780 --> 05:39.590
And I would say that if I didn't say this, I'll give X..

05:39.860 --> 05:47.180
So now you can see that X is nothing but the object of the class stamp.

05:48.380 --> 05:51.940
OK, so X is the object of the class.

05:52.910 --> 05:58.950
Now, by convention we give the classes a name that starts with a capital letter.

05:59.030 --> 06:03.730
That is why I have given this as a capital is Hiroto.

06:03.740 --> 06:06.320
I have given it as a capital B for the person.

06:06.890 --> 06:12.190
OK, now how X is now the difference to one new instance.

06:12.440 --> 06:18.100
So whenever we are creating this sample, so X is the new reference.

06:18.230 --> 06:24.980
So whenever I want to find out or run so certain properties or get to know about different properties

06:24.980 --> 06:28.910
of the instance, right now this is creating an instance.

06:29.180 --> 06:35.390
When I see a sample it is creating an instance, but I need a variable which will actually refer to

06:35.390 --> 06:36.080
that instance.

06:36.410 --> 06:43.420
It is something like you have created a placeholder X, which contains the instance of the object class.

06:43.430 --> 06:44.650
So this is the object.

06:44.720 --> 06:46.490
So X contains the object.

06:46.700 --> 06:52.310
Now, whenever you want to refer to anything inside that, you will simply say X dot and you will put

06:52.310 --> 06:55.410
the attribute or the method name.

06:55.430 --> 07:02.430
So if I have attributes Egilsay extorted, if I have an attribute start name, I will take extort name.

07:02.810 --> 07:10.190
Now, if I have any method which I have defined, then I will have to seize the let's say, eat so egg

07:10.190 --> 07:10.820
start to eat.

07:10.820 --> 07:13.250
And to run this I have to give it with abrasives.

07:13.970 --> 07:16.010
OK, so this is how we like this.

07:17.920 --> 07:23.460
Now here we have instantiated the sample class.

07:23.900 --> 07:28.210
When we did this, we have instantiated the sample class.

07:28.460 --> 07:33.050
Now inside of the class, we currently just have this bus.

07:33.660 --> 07:35.540
OK, we don't have any methods.

07:35.540 --> 07:37.130
We don't have any attributes.

07:37.820 --> 07:42.410
We had methods and attributes here, but we don't still don't know how to write that.

07:43.640 --> 07:54.250
So let's get a photo now, we can define these methods are not revealed so we can let you create a class.

07:54.260 --> 08:01.370
OK, now for that class, any characteristic of an object is called an attribute.

08:01.670 --> 08:07.520
So when you look at this particular class, this person has a few characteristics.

08:08.180 --> 08:09.860
So what are those characteristics?

08:10.010 --> 08:11.810
The name age rule.

08:12.080 --> 08:14.630
So these are different characteristics of the person.

08:15.100 --> 08:18.140
OK, these are called attributes.

08:19.100 --> 08:21.530
Apart from that, we have methods.

08:21.710 --> 08:26.850
Now, what are method methods in operation which we can perform on the object?

08:27.380 --> 08:37.280
So this create person display person E to walk, talk, whatever the person can do is called the method.

08:38.000 --> 08:46.070
OK, so now what we will be doing is we will be creating a class called Dog, OK, and we will create

08:46.070 --> 08:48.400
certain attributes of that dog.

08:48.410 --> 08:50.870
Let's say it's a breed or its name.

08:51.260 --> 08:59.810
And apart from that, we will give certain methods of the dog, which would be, let's say, barking.

09:00.020 --> 09:03.980
So Adolphine bark so we can create something like that.

09:04.280 --> 09:09.790
OK, so let us create that and then we are creating that.

09:10.070 --> 09:15.240
So when we are talking about this, so we will have to create attributes.

09:15.440 --> 09:23.590
Now when we are creating attributes, we will use a self operate on this soil.

09:23.600 --> 09:34.280
For Breteau means when we are writing self something, this means that this object dopp the characteristic.

09:35.450 --> 09:42.240
So whatever object I'm creating, so if I have creating object one, then the particular characteristics

09:42.410 --> 09:48.620
characteristic which is associated with this object is referred to by self-taught means or self.

09:49.790 --> 09:56.960
So when I say sell dot something, it means that I am referring to something which is specific to that

09:56.960 --> 10:00.270
particular class for specific to that particular object.

10:00.500 --> 10:05.100
So I can have two hundred people or three hundred people or thousands of people.

10:05.330 --> 10:10.800
So for each and every person there will be a different name, different age, different groups.

10:11.090 --> 10:12.650
And how do I refer to that?

10:12.650 --> 10:19.270
I refer to that using the object, dog name, object, dot age, object or drooly.

10:20.570 --> 10:22.980
Let's see how we can do that.

10:24.980 --> 10:30.250
So the first thing which we will be doing is we will create a class.

10:30.560 --> 10:34.520
So we have created a class and we see dog.

10:34.580 --> 10:36.410
So this is our class dog.

10:36.800 --> 10:42.620
And previously what we have done is we simply said, boss, so this simply created the dog class.

10:43.140 --> 10:47.000
Now what we can do is we can create the function.

10:47.030 --> 10:49.180
Now there is a specific method.

10:49.460 --> 10:53.230
Whatever functions are present inside a class, they are called a method.

10:53.570 --> 11:00.620
So the first method which we have in any class is the init method.

11:00.980 --> 11:02.840
OK, how do we define that?

11:02.840 --> 11:14.430
We will see this double underscored it double in the school and it will be set by default.

11:14.990 --> 11:21.200
This is something which you will be providing it every time when you are writing this in a method.

11:21.740 --> 11:31.790
OK, and this init method, what will it do is when you are creating an object out of this class, this

11:31.790 --> 11:34.560
function will run by default.

11:35.960 --> 11:43.520
So when we saw these two functions create person and display person, we have to run these.

11:43.970 --> 11:46.850
When we created person, these did not run.

11:47.180 --> 11:49.280
We had to run these separately.

11:50.240 --> 11:51.680
We are to run these separately.

11:51.950 --> 12:00.590
But now when we are creating this đinđić, this init method will run on its own as soon as you create

12:00.740 --> 12:02.630
an instance of this class.

12:02.900 --> 12:13.460
OK, so let's run this and I'll simply print and I'll say dog created.

12:13.940 --> 12:15.860
OK, dog object created.

12:17.450 --> 12:23.810
OK, yes, I have created this sum and on these I do object.

12:24.110 --> 12:27.590
So when I run this what each objected to sink object created.

12:27.590 --> 12:28.490
Object created.

12:28.940 --> 12:32.050
So this I have done for this particular class.

12:32.420 --> 12:36.590
Now let's say I want to provide some attribute to it.

12:36.920 --> 12:38.930
OK, now what is my attribute.

12:38.930 --> 12:42.820
I want to put in that, I want to give the brain also along with.

12:43.170 --> 13:00.720
So Sabri Anayansi says dog breed is equal to breed now this breed is nothing but this one and this breed

13:01.200 --> 13:03.030
is the attribute, OK?

13:03.060 --> 13:06.600
This is the attribute I could have given any other variable also.

13:06.600 --> 13:12.360
But this is the simplest way of doing it without creating any confusion if you're using the same name

13:12.360 --> 13:12.660
here.

13:13.170 --> 13:16.560
This will actually avoid confusion, I think would have created something else.

13:16.560 --> 13:19.350
Also, I'd say breed and insiders.

13:19.350 --> 13:28.080
I can say eggs and I can put eggs and say this doesn't make a difference, but I'm reediting breed here

13:28.080 --> 13:29.760
for simplicity.

13:32.040 --> 13:35.150
OK, now this breed has been created.

13:35.400 --> 13:38.250
Now I will simply run this.

13:38.250 --> 13:44.570
So when I create some dog object, I have to provide this breed because it will be needing it.

13:45.000 --> 13:49.960
So if I run it this way, it will give me a letter saying missing one required position.

13:49.980 --> 13:53.220
Like many breeders, it is expecting me to provide a breed.

13:53.430 --> 13:56.820
So I will simply say lamb.

13:58.080 --> 14:01.020
And here I say, let's see, Husky.

14:01.720 --> 14:08.640
OK, so these are the two breeds which I have and I found this so you can see Dog Love and a husky has

14:08.640 --> 14:09.390
been created.

14:09.780 --> 14:14.130
Now, apart from this, what you can do is you can also bring the details and everything.

14:14.430 --> 14:26.880
So for granted the detail again, you can see the whole object has been created and the breed is comma.

14:27.210 --> 14:29.090
So dog breed.

14:29.280 --> 14:32.250
So wherever you will be using this attribute, right.

14:32.490 --> 14:35.070
You will be using it using the self phone.

14:36.360 --> 14:40.270
So wherever I want to use the attribute, I will see a self-portrait.

14:40.680 --> 14:45.180
This will only mean that I want to use the breed which is associated with my object.

14:45.960 --> 14:49.260
So I run this again so you can see that it is giving the breed.

14:49.270 --> 14:53.100
So I have created two different objects on these objects.

14:53.100 --> 14:56.600
Have the relevant details about this.

14:56.820 --> 14:59.430
Now I can also do something like after this.

14:59.430 --> 15:04.380
I can also see I'm not a breed, so this will give me the details.

15:04.410 --> 15:05.970
So it's saying it is lab.

15:06.300 --> 15:11.220
It is saying don't breed is Huskie, so it will give me the details accordingly.

15:11.550 --> 15:13.530
If I put print here then it'll show.

15:18.930 --> 15:20.180
So this is what we do.

15:21.320 --> 15:24.630
Now let's break down everything.

15:24.870 --> 15:28.970
So the special method in it is present here.

15:28.980 --> 15:35.320
This each attribute in a class definition begins with a reference to the instance object.

15:35.350 --> 15:38.730
OK, so everything will begin with the.

15:40.680 --> 15:41.760
Object of the.

15:43.380 --> 15:46.870
Plus, now it is by convention himself.

15:46.890 --> 15:54.840
So this is my convention given I said, OK, now here we have the breed, this breed is nothing but

15:54.840 --> 15:57.930
the argument which is giving, which we are giving inside this.

15:58.110 --> 16:02.490
So by going by convention, we are using in this way and we are putting greed inside.

16:02.490 --> 16:04.050
This was simply simplicity.

16:04.510 --> 16:11.850
OK, now the value which is parsed during the class and instantiation is this breed values.

16:11.910 --> 16:13.320
We are passing this here.

16:13.740 --> 16:17.400
That is very it is taking the value in the IT by default.

16:17.670 --> 16:23.990
I'm saving it inside this breed and running this so this init method will run by default.

16:24.000 --> 16:29.940
We don't have to do anything to run this separately if we create any other method.

16:29.940 --> 16:32.960
So to run that method, I have to run it separately.

16:33.180 --> 16:49.080
So if let's say I do something like this printer and I just put it like this and I say, print, hi,

16:49.230 --> 16:58.200
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

16:58.200 --> 16:58.590
this.

16:58.770 --> 17:04.170
So to run this I'll have to see, see some dog print.

17:04.950 --> 17:06.980
OK then only drylands.

17:07.290 --> 17:15.930
See it is printing it now again if I want to refer to the breed I'll have to see selectivity.

17:15.960 --> 17:22.500
I just simply give it so it's not taking it because we have not used the self operator because it is

17:22.500 --> 17:23.060
not defined.

17:23.340 --> 17:26.140
So I have to give, said Dr..

17:29.480 --> 17:31.620
Breed them.

17:32.270 --> 17:40.420
OK, now we have created two instances of the dog, Lansdorp is some unknown, OK?

17:40.640 --> 17:43.430
And they do have two different breed.

17:44.930 --> 17:50.990
OK, and these are the attributes which can be accessed using Dornberg green and some don't breed.

17:51.890 --> 17:53.450
OK, next.

17:54.320 --> 17:57.950
Now, we don't have any bad instances of the breed.

17:58.310 --> 18:05.200
OK, if you see Prenter has opened, this is up by breed, does not have a parenthesis after.

18:05.660 --> 18:11.420
OK, now these glass object attributes are the same for any instance of the class.

18:11.750 --> 18:17.670
OK, so we could create the attribute species of the for the dog.

18:17.910 --> 18:24.930
OK, now the dog's regardless of their breed, name or other attribute will always be mammals.

18:25.460 --> 18:29.590
OK, so we apply this logic in this particular manner.

18:29.600 --> 18:36.500
So we just apply this particular logic that if let's say we have something which is common to all those

18:36.890 --> 18:40.390
attributes or for all the objects of this class.

18:40.580 --> 18:47.450
So how will we do that so far that what we can simply do is we can provide something like, OK, so

18:47.450 --> 18:55.940
all the attributes will be provided inside the functions and the common ones.

18:56.310 --> 19:01.910
That is something the ladybirds or any other words which are common to all the.

19:03.910 --> 19:07.470
Objects of the class will be provided outside, OK?

19:07.690 --> 19:15.680
I can use a display and I can see the to be fuelcell so I can get the species for Don, because mammal

19:15.760 --> 19:16.620
is common for all.

19:16.840 --> 19:19.020
So I can see it for all of these.

19:20.950 --> 19:25.630
The next thing which we will all learn about is methods.

19:25.840 --> 19:29.190
So we will look that in the next session.
