1
00:00:00,000 --> 00:00:00,000
Hello guys.

2
00:00:00,000 --> 00:00:03,000
So we are going to continue the discussion with respect to Python.

3
00:00:03,000 --> 00:00:07,000
And in this video we are going to talk about the most important module that is called as oops where

4
00:00:07,000 --> 00:00:10,000
we'll be discussing about classes and objects.

5
00:00:10,000 --> 00:00:15,000
Now, object oriented programming is a programming paradigm that uses objects to design application

6
00:00:15,000 --> 00:00:17,000
and computer programs, right?

7
00:00:17,000 --> 00:00:21,000
Oops allows us for modeling real world scenarios using classes and objects.

8
00:00:21,000 --> 00:00:26,000
Now any end to end projects that you are specifically going to create, we really need to use classes.

9
00:00:26,000 --> 00:00:27,000
We need to use objects.

10
00:00:27,000 --> 00:00:30,000
This increases the reusability of the code.

11
00:00:30,000 --> 00:00:36,000
And if I talk about developing real world use cases, we will be able to use it efficiently, like we'll

12
00:00:36,000 --> 00:00:40,000
be able to develop that application efficiently with the help of classes and objects.

13
00:00:40,000 --> 00:00:45,000
Now to give you a basic example of class, let's let's see the definition of class.

14
00:00:45,000 --> 00:00:49,000
So class is nothing but it is a blueprint for creating objects okay.

15
00:00:49,000 --> 00:00:53,000
It will be having separate attributes and separate methods Okay.

16
00:00:53,000 --> 00:00:55,000
Let's say that I go ahead and create a class okay.

17
00:00:55,000 --> 00:00:59,000
So let's give a basic example over here how to create a class.

18
00:00:59,000 --> 00:01:00,000
We'll see this.

19
00:01:00,000 --> 00:01:03,000
So here we use a keyword which is called as class.

20
00:01:03,000 --> 00:01:05,000
And here we will give the class name.

21
00:01:05,000 --> 00:01:09,000
Let's say that I'm going to create a class name which is called as car okay.

22
00:01:09,000 --> 00:01:12,000
Now car is nothing but it is a class okay.

23
00:01:12,000 --> 00:01:15,000
And uh, it is a blueprint of creating objects.

24
00:01:15,000 --> 00:01:17,000
Now I'll show you how to create an object.

25
00:01:17,000 --> 00:01:21,000
Okay, so let's say that this is I'm just writing or I'm creating an empty car.

26
00:01:21,000 --> 00:01:22,000
Right?

27
00:01:22,000 --> 00:01:25,000
Now, when I say creating an object, right?

28
00:01:25,000 --> 00:01:26,000
Car may be of different type.

29
00:01:26,000 --> 00:01:28,000
It may be of different different brand.

30
00:01:28,000 --> 00:01:28,000
Right.

31
00:01:28,000 --> 00:01:29,000
So I may go ahead and create.

32
00:01:29,000 --> 00:01:32,000
Hey, uh, first of all, I'll go ahead and create an Audi object.

33
00:01:32,000 --> 00:01:33,000
Right.

34
00:01:33,000 --> 00:01:35,000
So Audi object, it is a type of car.

35
00:01:35,000 --> 00:01:38,000
So I will go ahead and use the same blueprint and create this particular object.

36
00:01:38,000 --> 00:01:39,000
Right.

37
00:01:39,000 --> 00:01:43,000
Similarly I may go ahead and take a different variety of car.

38
00:01:43,000 --> 00:01:48,000
Let's say this is BMW, and here I may again use this as an uh, or instantiate from this particular

39
00:01:48,000 --> 00:01:50,000
class, right, to create this particular object.

40
00:01:50,000 --> 00:01:51,000
So this is nothing.

41
00:01:51,000 --> 00:01:56,000
But if I go ahead and print what is the type of Audi.

42
00:01:56,000 --> 00:01:56,000
Right.

43
00:01:56,000 --> 00:02:00,000
So you will be able to see that if I execute this it is nothing.

44
00:02:00,000 --> 00:02:03,000
But it is a it is also class.

45
00:02:03,000 --> 00:02:06,000
But this is exactly an object over here, right?

46
00:02:06,000 --> 00:02:11,000
The reason why I'm saying it as an object, because we have instantiated from this specific class,

47
00:02:11,000 --> 00:02:12,000
which is called as car.

48
00:02:12,000 --> 00:02:13,000
Okay.

49
00:02:13,000 --> 00:02:16,000
And similarly, uh, you can just imagine, right.

50
00:02:16,000 --> 00:02:18,000
What class is it is a real world entity.

51
00:02:18,000 --> 00:02:18,000
Okay.

52
00:02:18,000 --> 00:02:21,000
And it is also called as a blueprint.

53
00:02:21,000 --> 00:02:27,000
And just by using this specific class car, I can create different objects which may be using the features

54
00:02:27,000 --> 00:02:28,000
of this specific car.

55
00:02:28,000 --> 00:02:28,000
Right.

56
00:02:28,000 --> 00:02:30,000
Like we have Audi, BMW and all.

57
00:02:30,000 --> 00:02:31,000
Okay.

58
00:02:31,000 --> 00:02:38,000
Now, uh, let me just go ahead and probably explain more about it because I have not still, uh, discussed

59
00:02:38,000 --> 00:02:44,000
about attributes and methods, which we also called it as instance variable or instance methods.

60
00:02:44,000 --> 00:02:45,000
Okay.

61
00:02:45,000 --> 00:02:48,000
So if I probably also go ahead and print this Audi.

62
00:02:48,000 --> 00:02:50,000
So if I go ahead and print Audi what will I get.

63
00:02:50,000 --> 00:02:56,000
It will be showing that hey this is a car object at this specific memory location, okay?

64
00:02:56,000 --> 00:02:59,000
And similarly, if I go ahead and go ahead and print BMW.

65
00:02:59,000 --> 00:03:00,000
Right.

66
00:03:00,000 --> 00:03:05,000
So here also you'll be able to see, yes, it is showing that yes, it is a car object at this specific

67
00:03:05,000 --> 00:03:06,000
memory location.

68
00:03:06,000 --> 00:03:07,000
Right now.

69
00:03:07,000 --> 00:03:10,000
Let me just go ahead and include two more important things.

70
00:03:10,000 --> 00:03:15,000
Let's say I will go ahead and write instance variable and methods okay.

71
00:03:15,000 --> 00:03:15,000
Okay.

72
00:03:16,000 --> 00:03:17,000
Methods.

73
00:03:18,000 --> 00:03:20,000
Now let me just take another class.

74
00:03:20,000 --> 00:03:20,000
Okay.

75
00:03:20,000 --> 00:03:23,000
Let's say that I'm going to create a class called as dog.

76
00:03:23,000 --> 00:03:24,000
Right.

77
00:03:24,000 --> 00:03:26,000
Now dog is a blueprint right.

78
00:03:26,000 --> 00:03:30,000
And in order to define the attributes over here.

79
00:03:30,000 --> 00:03:30,000
Right.

80
00:03:30,000 --> 00:03:33,000
See uh, one way, if I probably take this already and.

81
00:03:33,000 --> 00:03:39,000
All right, if I just go ahead and write ord dot, let's say I want to go ahead and define one instance

82
00:03:39,000 --> 00:03:42,000
variable that is present inside the class.

83
00:03:42,000 --> 00:03:44,000
Let's say Audi has some windows right?

84
00:03:44,000 --> 00:03:47,000
I will just go ahead and write for write.

85
00:03:47,000 --> 00:03:49,000
This windows is basically for right.

86
00:03:49,000 --> 00:03:57,000
And if I go ahead and print Audi dot windows, then I will be able to see that I am able to get the

87
00:03:57,000 --> 00:03:57,000
answer.

88
00:03:57,000 --> 00:04:04,000
As for so, windows is a kind of attribute that is present inside the car, and for Audi it may be that

89
00:04:04,000 --> 00:04:07,000
I may have four windows for some other car.

90
00:04:07,000 --> 00:04:08,000
I may just have two windows.

91
00:04:08,000 --> 00:04:13,000
Like, let's say that I'm taking a very smaller car over there, which is just like a Tata Nano.

92
00:04:13,000 --> 00:04:17,000
Okay, it may be having four windows, but let's say that there is a new variety of car that may have

93
00:04:17,000 --> 00:04:18,000
two windows.

94
00:04:18,000 --> 00:04:20,000
So I can change that particular attribute values.

95
00:04:20,000 --> 00:04:23,000
And this is how we specifically define right.

96
00:04:23,000 --> 00:04:23,000
This is nothing.

97
00:04:23,000 --> 00:04:25,000
But this is a kind of attributes.

98
00:04:25,000 --> 00:04:31,000
But initializing attributes like this is not a proper way.

99
00:04:31,000 --> 00:04:34,000
The reason is very much simple why this is not a proper way.

100
00:04:34,000 --> 00:04:38,000
Because see, whenever I create another object, let's say that I'm going to create another object.

101
00:04:38,000 --> 00:04:40,000
Let's say this will be a Tata car.

102
00:04:40,000 --> 00:04:43,000
And now I will go ahead and initialize with car object.

103
00:04:43,000 --> 00:04:43,000
Right.

104
00:04:43,000 --> 00:04:45,000
I'll go ahead and create this particular object.

105
00:04:45,000 --> 00:04:48,000
Now I may go ahead and write Tata dot doors.

106
00:04:48,000 --> 00:04:48,000
Right.

107
00:04:48,000 --> 00:04:50,000
So this will be my another attribute.

108
00:04:50,000 --> 00:04:53,000
And let's say they are around five four doors over here Right?

109
00:04:53,000 --> 00:04:59,000
But if you see with respect to Audi, I did not created a attribute called a doors.

110
00:04:59,000 --> 00:05:03,000
Whereas over here I created something called as windows in that I did not create an attribute called

111
00:05:03,000 --> 00:05:04,000
as windows.

112
00:05:04,000 --> 00:05:04,000
Right.

113
00:05:04,000 --> 00:05:08,000
So if I go ahead and print tata dot windows, will I get anything.

114
00:05:08,000 --> 00:05:09,000
Let's see.

115
00:05:09,000 --> 00:05:15,000
So here you can see that I'll be getting an error saying that the car object has no attribute windows.

116
00:05:15,000 --> 00:05:15,000
Right.

117
00:05:15,000 --> 00:05:19,000
So defining the attributes in this way is not a proper way.

118
00:05:19,000 --> 00:05:25,000
So I will just show you another way how we can clearly define all the attributes and methods in the

119
00:05:25,000 --> 00:05:29,000
first hand while we are initializing, or while we are creating the objects itself.

120
00:05:29,000 --> 00:05:30,000
Right.

121
00:05:30,000 --> 00:05:33,000
So I'm going to take an example with respect to dog.

122
00:05:33,000 --> 00:05:33,000
Okay.

123
00:05:33,000 --> 00:05:37,000
And here uh, there is one very important function.

124
00:05:37,000 --> 00:05:44,000
See if I go ahead and write dir Directory of this specific class that is called a starter.

125
00:05:44,000 --> 00:05:45,000
Okay.

126
00:05:45,000 --> 00:05:50,000
Here you'll be seeing there will be a lot of different different inbuilt methods right.

127
00:05:50,000 --> 00:05:54,000
And each and every inbuilt methods will be doing something else right now.

128
00:05:54,000 --> 00:05:58,000
Since you can see that I have created an attribute called as doors, you will be also able to see that

129
00:05:58,000 --> 00:06:01,000
this doors will be available over here.

130
00:06:01,000 --> 00:06:04,000
Right inside this particular directory I will be talking about different.

131
00:06:04,000 --> 00:06:07,000
Different uh, over here methods.

132
00:06:07,000 --> 00:06:07,000
Right.

133
00:06:07,000 --> 00:06:09,000
What functionalities it usually does.

134
00:06:09,000 --> 00:06:14,000
But here I'm going to take about I'm going to talk about one method which is called as underscore underscore

135
00:06:14,000 --> 00:06:15,000
init underscore underscore.

136
00:06:15,000 --> 00:06:23,000
Now what this method is all about this method is called as constructor okay constructor.

137
00:06:23,000 --> 00:06:25,000
Now what does this specific method do.

138
00:06:25,000 --> 00:06:30,000
So if I go ahead and write definition underscore underscore init underscore underscore.

139
00:06:30,000 --> 00:06:36,000
If initially I want to define any attributes, I can make sure that with the help of this particular

140
00:06:36,000 --> 00:06:39,000
constructor at the first hand, I'll be defining.

141
00:06:39,000 --> 00:06:43,000
I'll be able to define all the attributes that will be available inside this particular class.

142
00:06:43,000 --> 00:06:47,000
Right now, in order to define it, let's say in dog.

143
00:06:47,000 --> 00:06:47,000
Right.

144
00:06:47,000 --> 00:06:50,000
Um, let's say I have two attributes over here.

145
00:06:50,000 --> 00:06:53,000
One is name and the other one is age.

146
00:06:53,000 --> 00:06:53,000
Right.

147
00:06:53,000 --> 00:06:59,000
So while I'm initializing, or while I am creating the object from a dog class, I have to make sure

148
00:06:59,000 --> 00:07:01,000
that I have to give this two attributes.

149
00:07:01,000 --> 00:07:02,000
Okay.

150
00:07:02,000 --> 00:07:06,000
During the runtime, I have to give this two values during the runtime when I create the object.

151
00:07:06,000 --> 00:07:12,000
Okay, now the best thing over here is that this is basically my parameter, right?

152
00:07:12,000 --> 00:07:17,000
And internally I will go ahead and create some instance variable.

153
00:07:17,000 --> 00:07:22,000
Now this instance variable are like some kind of properties that are available inside the dog class

154
00:07:22,000 --> 00:07:23,000
okay.

155
00:07:23,000 --> 00:07:29,000
And you know that I have to basically take this particular name and assign this name itself, because

156
00:07:29,000 --> 00:07:32,000
during the runtime I'm going to put this particular value.

157
00:07:32,000 --> 00:07:35,000
Now obviously I have written the same name.

158
00:07:35,000 --> 00:07:37,000
The variable name is almost same.

159
00:07:37,000 --> 00:07:41,000
So let me just go ahead and write one more parameter which is called as self okay.

160
00:07:41,000 --> 00:07:42,000
It is not compulsory.

161
00:07:42,000 --> 00:07:44,000
You always need to write self okay.

162
00:07:44,000 --> 00:07:46,000
You can write anything over here.

163
00:07:46,000 --> 00:07:46,000
You can write crush.

164
00:07:46,000 --> 00:07:48,000
You can write your name also.

165
00:07:48,000 --> 00:07:55,000
But self uh is a keyword which we specifically use, you know worldwide in terms of good practices we

166
00:07:55,000 --> 00:07:56,000
use self keyword.

167
00:07:56,000 --> 00:07:59,000
Right now this self keyword will be responsible.

168
00:07:59,000 --> 00:08:05,000
You know, in probably accessing the instance variable inside the class itself whenever we create an

169
00:08:05,000 --> 00:08:06,000
object.

170
00:08:06,000 --> 00:08:09,000
So here what I'm going to write I'm just going to say self dot name.

171
00:08:09,000 --> 00:08:15,000
Now this name that you will be seeing which is which is along with self dot name.

172
00:08:15,000 --> 00:08:19,000
This name is nothing, but it is my instance variable that is available inside the dog class.

173
00:08:19,000 --> 00:08:20,000
Okay.

174
00:08:20,000 --> 00:08:25,000
And this name is what is the parameter that I'm passing while creating the object?

175
00:08:25,000 --> 00:08:27,000
Okay, so here there are two parameters.

176
00:08:27,000 --> 00:08:31,000
One is self dot name and the second one that I'm actually going to go ahead and write.

177
00:08:31,000 --> 00:08:32,000
It is nothing but self dot.

178
00:08:33,000 --> 00:08:35,000
Uh age is equal to age.

179
00:08:35,000 --> 00:08:41,000
So this way I am initializing my entire class with a constructor.

180
00:08:41,000 --> 00:08:47,000
Now if I go ahead and create the object okay, now let's go ahead and create the objects right.

181
00:08:47,000 --> 00:08:50,000
You will be able to see that as soon as I go ahead and write.

182
00:08:50,000 --> 00:08:52,000
Hey, let's go ahead and create my object.

183
00:08:52,000 --> 00:08:52,000
Dog one.

184
00:08:52,000 --> 00:08:56,000
This will get initialized from dog okay.

185
00:08:56,000 --> 00:08:58,000
And here I'm going to give two parameters.

186
00:08:58,000 --> 00:09:02,000
If I execute like this it will tell me hey you're missing two required positional argument name and

187
00:09:02,000 --> 00:09:03,000
age.

188
00:09:03,000 --> 00:09:05,000
Because name and age is not given.

189
00:09:05,000 --> 00:09:10,000
As soon as I call this, what is internally going to happen is that it is going to call this constructor

190
00:09:10,000 --> 00:09:11,000
first.

191
00:09:11,000 --> 00:09:12,000
Okay?

192
00:09:12,000 --> 00:09:16,000
Because of this constructor, it is going to take all these values that is required for the instance

193
00:09:16,000 --> 00:09:16,000
variable.

194
00:09:16,000 --> 00:09:18,000
So here I need to provide two parameter.

195
00:09:18,000 --> 00:09:21,000
Let's say here I will go ahead and write buddy.

196
00:09:21,000 --> 00:09:23,000
And the age is three okay.

197
00:09:23,000 --> 00:09:28,000
Now if I go ahead and execute this print dog one okay.

198
00:09:28,000 --> 00:09:33,000
You will be able to see that I will be able to create a dog object at this specific memory location.

199
00:09:34,000 --> 00:09:37,000
Now this instance variable is their right name and age.

200
00:09:37,000 --> 00:09:51,000
Now let's go ahead and retrieve this dog One dot name and the next one is print dog one dot age.

201
00:09:51,000 --> 00:09:51,000
Right.

202
00:09:51,000 --> 00:09:56,000
So now if I go ahead and access this values, you'll be able to see that I'm able to get that value

203
00:09:56,000 --> 00:09:57,000
which is called as buddy and three.

204
00:09:57,000 --> 00:09:58,000
Right.

205
00:09:58,000 --> 00:10:01,000
Similarly, I can go ahead and create any number of dogs objects.

206
00:10:01,000 --> 00:10:01,000
Right.

207
00:10:01,000 --> 00:10:03,000
So I'll go ahead and write dog two.

208
00:10:03,000 --> 00:10:07,000
And again I will be using dog and I will go and give my parameters over here.

209
00:10:07,000 --> 00:10:11,000
Let's say I will give something like Lucy and the age is four.

210
00:10:11,000 --> 00:10:14,000
And I will be able to print the same thing over here.

211
00:10:14,000 --> 00:10:24,000
That is nothing but dog two dot name and similarly print dog to dot age, right?

212
00:10:24,000 --> 00:10:30,000
So here you will be able to see that I will be able to access this instance variable over here Now the

213
00:10:30,000 --> 00:10:37,000
best thing is that we have defined the instance variable initially in the constructor so that we cannot

214
00:10:37,000 --> 00:10:42,000
create any more, you know, whatever things is defined in the constructor, only those number of instance

215
00:10:42,000 --> 00:10:43,000
variable itself we can create.

216
00:10:43,000 --> 00:10:49,000
If tomorrow I require any more instance variable, I can just go ahead and write self dot that particular

217
00:10:49,000 --> 00:10:50,000
instance variable.

218
00:10:50,000 --> 00:10:53,000
And I'll assign the value based on the parameter that I pass over here.

219
00:10:53,000 --> 00:10:54,000
Right.

220
00:10:54,000 --> 00:10:59,000
So this is the best practice that we specifically use with respect to creating instance variables right.

221
00:10:59,000 --> 00:11:06,000
Now let's talk about instance method right now instance variable whenever we talk about it is some kind

222
00:11:06,000 --> 00:11:07,000
of properties.

223
00:11:07,000 --> 00:11:10,000
That dog that talks about dog right.

224
00:11:10,000 --> 00:11:14,000
So over here name and age are just like my properties for this particular dog.

225
00:11:14,000 --> 00:11:15,000
Right.

226
00:11:15,000 --> 00:11:16,000
It's ah these are nothing.

227
00:11:16,000 --> 00:11:18,000
But these are some kind of attributes.

228
00:11:18,000 --> 00:11:18,000
Right.

229
00:11:18,000 --> 00:11:24,000
Similarly, they may be methods which we also call this as instance methods like a dog may be barking.

230
00:11:24,000 --> 00:11:24,000
Right.

231
00:11:24,000 --> 00:11:26,000
It may be doing some kind of functionalities.

232
00:11:26,000 --> 00:11:27,000
Right.

233
00:11:27,000 --> 00:11:29,000
It may be running at a specific speed something.

234
00:11:29,000 --> 00:11:29,000
Right.

235
00:11:29,000 --> 00:11:30,000
So those are nothing.

236
00:11:30,000 --> 00:11:32,000
But those are basically instance method.

237
00:11:32,000 --> 00:11:37,000
Now let me show you how you can actually go ahead and create the instance methods.

238
00:11:37,000 --> 00:11:37,000
Right.

239
00:11:37,000 --> 00:11:40,000
So now I'm going to define a class with an instance method.

240
00:11:40,000 --> 00:11:46,000
So let's go ahead and define a class with instance methods okay.

241
00:11:46,000 --> 00:11:50,000
Now in order to define a class with instance method again I will go ahead and write class dog.

242
00:11:50,000 --> 00:11:51,000
Okay.

243
00:11:51,000 --> 00:11:56,000
Now as you know that I will be using my init constructor.

244
00:11:56,000 --> 00:12:00,000
So I will go ahead and write definition underscore underscore init underscore underscore.

245
00:12:00,000 --> 00:12:02,000
Here I will use a self keyword.

246
00:12:02,000 --> 00:12:05,000
Let's say that there are two parameters or two features that I'm going to use.

247
00:12:05,000 --> 00:12:06,000
That is name and age.

248
00:12:06,000 --> 00:12:08,000
These are my two instance variable.

249
00:12:08,000 --> 00:12:13,000
I can also say it as properties, attributes, anything you can specifically talk about.

250
00:12:13,000 --> 00:12:17,000
But all these parameters are basically talking about this dog class itself, right?

251
00:12:17,000 --> 00:12:19,000
These are the properties of them.

252
00:12:19,000 --> 00:12:19,000
Right.

253
00:12:19,000 --> 00:12:21,000
And this is what I'm going to pass in the runtime.

254
00:12:21,000 --> 00:12:23,000
Now I'll go ahead and create my properties.

255
00:12:23,000 --> 00:12:26,000
So I'll go ahead and write self dot name is equal to name.

256
00:12:26,000 --> 00:12:31,000
Then I'm going to write self dot age is equal to age Okay, now this is fine.

257
00:12:31,000 --> 00:12:34,000
Right now once I create my constructor.

258
00:12:34,000 --> 00:12:38,000
Now I'm going to write create some instance method that is related to dog.

259
00:12:38,000 --> 00:12:41,000
Let's say the dog will be barking right.

260
00:12:41,000 --> 00:12:45,000
So and different different dog can bark in a different different way.

261
00:12:45,000 --> 00:12:47,000
So here also I'll be using the self keyword.

262
00:12:47,000 --> 00:12:48,000
The reason is very simple.

263
00:12:48,000 --> 00:12:52,000
So that inside this method also I will be able to use this instance variable okay.

264
00:12:52,000 --> 00:12:55,000
That is the reason we provide this self keyword over here.

265
00:12:55,000 --> 00:13:02,000
Now I will go ahead and write print okay some functionality or some uh, some print statement.

266
00:13:02,000 --> 00:13:07,000
I will write over here and I'll go ahead and write self dot name right self dot name basically means

267
00:13:07,000 --> 00:13:08,000
the same attribute.

268
00:13:08,000 --> 00:13:12,000
I'm calling it over here says woof.

269
00:13:12,000 --> 00:13:12,000
Right.

270
00:13:12,000 --> 00:13:16,000
So this is the sound uh, specific dog makes uh in generic.

271
00:13:16,000 --> 00:13:17,000
Okay.

272
00:13:17,000 --> 00:13:18,000
So here you can actually see over here.

273
00:13:18,000 --> 00:13:19,000
Right.

274
00:13:19,000 --> 00:13:25,000
And uh, if I probably, uh, just consider this, this is one of the instance method.

275
00:13:25,000 --> 00:13:26,000
Okay.

276
00:13:26,000 --> 00:13:28,000
Now what I'm going to do I'll go ahead and create my object.

277
00:13:28,000 --> 00:13:30,000
Let's say that this is my dog one.

278
00:13:30,000 --> 00:13:33,000
And here I'm just going to call dog.

279
00:13:34,000 --> 00:13:37,000
And let me just give the values here I will be giving buddy.

280
00:13:37,000 --> 00:13:39,000
Comma three is the age.

281
00:13:39,000 --> 00:13:46,000
Now I can use this object and call this particular function right method right.

282
00:13:46,000 --> 00:13:49,000
This method is nothing, but it is basically called as bark.

283
00:13:49,000 --> 00:13:55,000
Okay, now if I go ahead and just execute this, you'll be able to see that I will be getting that print

284
00:13:55,000 --> 00:13:57,000
says buddy says HUF right.

285
00:13:57,000 --> 00:14:00,000
Now tomorrow I want to go ahead and create my another dog two.

286
00:14:00,000 --> 00:14:01,000
Okay.

287
00:14:01,000 --> 00:14:07,000
And let's say this dog two is basically having the name as Lucy, okay.

288
00:14:07,000 --> 00:14:09,000
And the age is four, right.

289
00:14:09,000 --> 00:14:13,000
If I go ahead and just go ahead and call this dog two dot bark.

290
00:14:13,000 --> 00:14:18,000
So here you will be able to see that I'll be able to see it get Lucy says woof right.

291
00:14:18,000 --> 00:14:19,000
So buddy says woof.

292
00:14:19,000 --> 00:14:20,000
Lucy says woof.

293
00:14:20,000 --> 00:14:22,000
Now this is the function.

294
00:14:22,000 --> 00:14:27,000
And based on different different dog types, you can just consider that the object is nothing but different,

295
00:14:27,000 --> 00:14:29,000
different dog types, right?

296
00:14:29,000 --> 00:14:33,000
They're using the same properties and they're using the same method.

297
00:14:33,000 --> 00:14:36,000
And this will be relative to that specific object.

298
00:14:36,000 --> 00:14:42,000
So that is the reason over here in the definition we have clearly written as a class is a blueprint

299
00:14:42,000 --> 00:14:43,000
for creating objects.

300
00:14:43,000 --> 00:14:47,000
And it has its own attribute and methods which can be used by this objects.

301
00:14:47,000 --> 00:14:48,000
Right.

302
00:14:48,000 --> 00:14:53,000
So I hope you got an idea with respect to this, and I hope you are able to understand this.

303
00:14:53,000 --> 00:14:53,000
Okay.

304
00:14:54,000 --> 00:14:58,000
Now, uh, let's design a better example for you.

305
00:14:58,000 --> 00:14:59,000
Okay.

306
00:14:59,000 --> 00:15:04,000
So here we are going to take this example which is called as modeling.

307
00:15:06,000 --> 00:15:11,000
Modeling a bank account okay.

308
00:15:11,000 --> 00:15:13,000
So now let's go ahead and do this okay.

309
00:15:13,000 --> 00:15:20,000
So here you'll be able to see I will define a class for bank account.

310
00:15:20,000 --> 00:15:20,000
Okay.

311
00:15:20,000 --> 00:15:24,000
First of all, now you know in a bank account you will be able to withdraw money, you will be able

312
00:15:24,000 --> 00:15:25,000
to deposit money.

313
00:15:25,000 --> 00:15:28,000
And you will be also able to see the balance in the money.

314
00:15:28,000 --> 00:15:28,000
Right.

315
00:15:28,000 --> 00:15:32,000
So here, first of all, how do we design this entire application with the help of classes.

316
00:15:32,000 --> 00:15:37,000
So I'm just going to use class with respect to bank account okay.

317
00:15:37,000 --> 00:15:41,000
It is always a good practice that you use capital letter whenever you are defining a class.

318
00:15:41,000 --> 00:15:44,000
Then I'm going to use my constructor.

319
00:15:44,000 --> 00:15:47,000
That is underscore underscore init underscore underscore.

320
00:15:47,000 --> 00:15:50,000
Let's say that what all parameters I'm going to probably give over here.

321
00:15:50,000 --> 00:15:54,000
One is owner information and the next is balance.

322
00:15:54,000 --> 00:15:58,000
By default whenever we create an account the balance will be zero okay.

323
00:15:58,000 --> 00:16:01,000
So by default I'm giving some values over here.

324
00:16:01,000 --> 00:16:05,000
Then I will go ahead and write self dot owner is equal to owner.

325
00:16:05,000 --> 00:16:12,000
So and again guys you may be thinking should this particular attribute be same to this particular parameter

326
00:16:12,000 --> 00:16:12,000
name?

327
00:16:12,000 --> 00:16:13,000
The answer is no right?

328
00:16:13,000 --> 00:16:19,000
You can write as your own, but I'm just following the good practices that many of the developer usually

329
00:16:19,000 --> 00:16:19,000
follows.

330
00:16:19,000 --> 00:16:21,000
Then I'll go ahead and write.

331
00:16:21,000 --> 00:16:24,000
Self dot balance is equal to balance.

332
00:16:24,000 --> 00:16:27,000
Okay, now here you can see that I have created my bank account.

333
00:16:27,000 --> 00:16:28,000
Perfect.

334
00:16:28,000 --> 00:16:30,000
These are my attributes right?

335
00:16:30,000 --> 00:16:31,000
Owner and balance.

336
00:16:31,000 --> 00:16:33,000
We also call this as instance variable.

337
00:16:33,000 --> 00:16:37,000
Now the next thing is that I will go ahead and define my instance method.

338
00:16:37,000 --> 00:16:41,000
So first of all we'll go and create one method which is called as deposit.

339
00:16:41,000 --> 00:16:43,000
And here I'm going to give self.

340
00:16:43,000 --> 00:16:46,000
And one parameter that I will give is amount okay.

341
00:16:46,000 --> 00:16:51,000
Amount is like how much we really need to deposit as the parameter I'm giving okay.

342
00:16:51,000 --> 00:16:59,000
Now whenever I try to add money in my account through deposit, I have to probably increase my balance

343
00:16:59,000 --> 00:17:03,000
now in order to get the excess of the balance again, I have to use self dot balance.

344
00:17:03,000 --> 00:17:07,000
Keyword plus is equal to this specific amount, right?

345
00:17:07,000 --> 00:17:12,000
And this is what we are basically doing with respect to the balance deposit function.

346
00:17:12,000 --> 00:17:15,000
And I will just go ahead and print and go ahead and write.

347
00:17:15,000 --> 00:17:24,000
Hey uh amount is deposited, new balances.

348
00:17:24,000 --> 00:17:26,000
I'm just going to write some print statement.

349
00:17:26,000 --> 00:17:29,000
New balances, self dot balance okay.

350
00:17:29,000 --> 00:17:33,000
Self dot balance I cannot directly use balance because this is nothing.

351
00:17:33,000 --> 00:17:36,000
But it is an instance variable that is available over here okay.

352
00:17:36,000 --> 00:17:40,000
Now the next function that I'm actually going to create is nothing but withdraw.

353
00:17:40,000 --> 00:17:43,000
So I'm going to write withdraw, definition withdraw.

354
00:17:43,000 --> 00:17:47,000
And here I'm going to use self comma amount okay.

355
00:17:47,000 --> 00:17:57,000
And with respect to this if amount is greater than self dot balance okay I'm just saying that hey if

356
00:17:57,000 --> 00:18:01,000
I'm withdrawing, first of all I need to check whether the amount is greater than self dot balance.

357
00:18:01,000 --> 00:18:05,000
If the amount is greater than self dot balance.

358
00:18:05,000 --> 00:18:09,000
And if I am trying to withdraw, then obviously this should not be allowed.

359
00:18:09,000 --> 00:18:10,000
And I'll just go ahead and print.

360
00:18:10,000 --> 00:18:11,000
Hey.

361
00:18:11,000 --> 00:18:12,000
Insufficient funds.

362
00:18:13,000 --> 00:18:15,000
Insufficient funds.

363
00:18:15,000 --> 00:18:16,000
Okay.

364
00:18:16,000 --> 00:18:20,000
And finally I'll close this right now.

365
00:18:20,000 --> 00:18:25,000
If this is not satisfied, then what I will do, I'll go ahead and write my else condition.

366
00:18:25,000 --> 00:18:29,000
And this time I have to subtract it from my balance account.

367
00:18:29,000 --> 00:18:33,000
So I will go ahead and write minus equal to this specific amount.

368
00:18:33,000 --> 00:18:35,000
Okay, so I hope you are able to understand this.

369
00:18:35,000 --> 00:18:41,000
Now if the amount is greater than self dot balance I will say hey, it is insufficient funds.

370
00:18:41,000 --> 00:18:47,000
But if this is not true, if the amount is less than self dot balance, I should be able to withdraw

371
00:18:47,000 --> 00:18:47,000
it.

372
00:18:47,000 --> 00:18:52,000
So here you will be able to see that I am writing self dot balance minus is equal to that specific amount.

373
00:18:52,000 --> 00:19:02,000
And here I will go ahead and print and say that by using an f string say that hey this amount is withdrawn.

374
00:19:04,000 --> 00:19:06,000
Withdrawn okay.

375
00:19:06,000 --> 00:19:07,000
New balance.

376
00:19:09,000 --> 00:19:14,000
New balance is self dot balance right.

377
00:19:15,000 --> 00:19:16,000
So this is perfect.

378
00:19:16,000 --> 00:19:20,000
So I've created two instance method along with that two instance variable.

379
00:19:20,000 --> 00:19:22,000
And finally one more method I will go ahead and create.

380
00:19:22,000 --> 00:19:24,000
And you can create any number of methods.

381
00:19:24,000 --> 00:19:26,000
I will say hey get balance okay.

382
00:19:26,000 --> 00:19:28,000
And here I will again use the self keyword.

383
00:19:28,000 --> 00:19:34,000
And all we have to do over here is that I will just go ahead and write return self dot balance.

384
00:19:34,000 --> 00:19:37,000
I just need to return the balance in my account.

385
00:19:37,000 --> 00:19:38,000
Okay, done.

386
00:19:40,000 --> 00:19:43,000
Now you'll be able to see the balance amount and all.

387
00:19:43,000 --> 00:19:44,000
Everything is there.

388
00:19:44,000 --> 00:19:46,000
Now let's go ahead and create an object.

389
00:19:46,000 --> 00:19:48,000
So I will go ahead and create an object.

390
00:19:48,000 --> 00:19:51,000
Now you can perform any kind of operation that you really want.

391
00:19:51,000 --> 00:19:55,000
So while creating an object I have to make sure that I create an account.

392
00:19:55,000 --> 00:19:59,000
So first of all I will go ahead and write bank account okay which is my class.

393
00:19:59,000 --> 00:20:05,000
And when I call this particular bank account I have to give two attributes that is owner and balance.

394
00:20:05,000 --> 00:20:07,000
Write owner over here is nothing.

395
00:20:07,000 --> 00:20:09,000
But I'll go ahead and say crush.

396
00:20:09,000 --> 00:20:15,000
And initially let's say my balance is I am depositing around ₹500 okay.

397
00:20:15,000 --> 00:20:17,000
Or let's say ₹5,000.

398
00:20:17,000 --> 00:20:17,000
Okay.

399
00:20:17,000 --> 00:20:24,000
Now let me just go ahead and print the count dot balance.

400
00:20:24,000 --> 00:20:25,000
So this is crush account right.

401
00:20:25,000 --> 00:20:28,000
So here we'll be able to see that I'm getting ₹5,000.

402
00:20:28,000 --> 00:20:34,000
Now let's say that I want to call this instance method okay.

403
00:20:34,000 --> 00:20:35,000
Where I want to withdraw some money.

404
00:20:35,000 --> 00:20:36,000
Okay.

405
00:20:36,000 --> 00:20:38,000
So first of all let's go ahead and do some deposit.

406
00:20:38,000 --> 00:20:42,000
Let's say that I got my salary and my salary is ₹100.

407
00:20:42,000 --> 00:20:44,000
And I've deposited it okay.

408
00:20:44,000 --> 00:20:49,000
So if I go ahead and print or if I just go ahead and execute this, you'll be able to see that I'm getting

409
00:20:49,000 --> 00:20:54,000
a message saying that, hey, 100 is deposited, new balance is 5100 right now.

410
00:20:54,000 --> 00:20:57,000
Let me just go ahead and withdraw some money.

411
00:20:57,000 --> 00:21:04,000
Let's say that I want to withdraw account dot withdraw is nothing, but I want to withdraw ₹300.

412
00:21:04,000 --> 00:21:06,000
So I'll just go ahead and execute it.

413
00:21:06,000 --> 00:21:07,000
Now here you can see.

414
00:21:07,000 --> 00:21:09,000
Hey, 300 is withdrawn.

415
00:21:09,000 --> 00:21:12,000
New balance is 4800 right now.

416
00:21:12,000 --> 00:21:18,000
Finally, if I want to get the complete account balance, I should be able to just call print account

417
00:21:18,000 --> 00:21:20,000
dot get balance.

418
00:21:20,000 --> 00:21:22,000
And that is what I'm actually going to execute it.

419
00:21:22,000 --> 00:21:24,000
And here you can see I'm getting 4800.

420
00:21:24,000 --> 00:21:31,000
So here in just front of you I have designed the entire bank account with respect to all the operations

421
00:21:31,000 --> 00:21:36,000
with the help of class, instance variable and instance method.

422
00:21:36,000 --> 00:21:41,000
So I hope you are able to understand this, uh, completely with respect to this particular example

423
00:21:41,000 --> 00:21:43,000
of bank account and all.

424
00:21:43,000 --> 00:21:47,000
Um, as we go ahead, we'll be talking more about different, different examples, right.

425
00:21:47,000 --> 00:21:51,000
This is just to give you an idea of how powerful this class is.

426
00:21:51,000 --> 00:21:55,000
Ah, but please make sure that always make sure you keep a note of all the indentation.

427
00:21:55,000 --> 00:21:56,000
How to probably create it.

428
00:21:57,000 --> 00:22:01,000
Uh, you need to understand very much clearly that this init is nothing, but it is a constructor.

429
00:22:01,000 --> 00:22:02,000
This.

430
00:22:02,000 --> 00:22:04,000
Ah, my instance variable.

431
00:22:04,000 --> 00:22:09,000
This is ah, my instance methods and I can probably go ahead and write any number of instance method

432
00:22:09,000 --> 00:22:10,000
that I want.

433
00:22:10,000 --> 00:22:15,000
And the importance of self keyword is to use this kind of instance variable wherever we want.

434
00:22:15,000 --> 00:22:20,000
Inside this particular instance method, right out of this class, I cannot use self keyword.

435
00:22:20,000 --> 00:22:22,000
That is very much clear, right?

436
00:22:22,000 --> 00:22:26,000
So I hope you are able to understand this, uh, entire video.

437
00:22:26,000 --> 00:22:31,000
So finally I will just write some conclusion saying that What?

438
00:22:31,000 --> 00:22:32,000
All things.

439
00:22:32,000 --> 00:22:36,000
Uh, is important with respect to why this class is are important.

440
00:22:36,000 --> 00:22:39,000
So here object oriented programming is very, very much important.

441
00:22:39,000 --> 00:22:43,000
It allows you to model real world scenarios using class an object.

442
00:22:43,000 --> 00:22:47,000
In this lesson you learn how to create a class in objects, define instance variable and method and

443
00:22:47,000 --> 00:22:49,000
use them to perform various operation.

444
00:22:49,000 --> 00:22:50,000
Right?

445
00:22:50,000 --> 00:22:52,000
So yes, this was it for my side.

446
00:22:52,000 --> 00:22:53,000
I hope you liked this particular video.

447
00:22:53,000 --> 00:22:55,000
I will see you all in the next video.

448
00:22:55,000 --> 00:22:55,000
Thank you.

