1 00:00:00,000 --> 00:00:02,100 Friends here our concept is 2 00:00:02,100 --> 00:00:04,500 class and object attributes. 3 00:00:04,500 --> 00:00:07,500 See already we know simply what is the class. So class is 4 00:00:07,500 --> 00:00:10,100 a template or blueprint to create an object. 5 00:00:10,100 --> 00:00:12,800 So once if you have a template from that we can create any 6 00:00:12,800 --> 00:00:17,400 number of objects. And class is the combination of attributes 7 00:00:17,400 --> 00:00:20,900 and methods. So basically attributes are like variables, 8 00:00:20,900 --> 00:00:22,700 [no audio] 9 00:00:22,700 --> 00:00:26,310 and we can define attributes for class and objects. 10 00:00:26,300 --> 00:00:29,700 I mean for class level we can define some variables, and for 11 00:00:29,700 --> 00:00:32,210 object level we can define some variables. 12 00:00:32,200 --> 00:00:35,400 Let me explain this concept with the help of a simple Python 13 00:00:35,400 --> 00:00:40,300 script. So I am saving my script name as 'working_on_attributes.py'. 14 00:00:41,100 --> 00:00:44,100 So guys suppose I am writing a simple Python script 15 00:00:44,100 --> 00:00:49,110 or program to maintain the data for employees. 16 00:00:49,100 --> 00:00:51,809 Suppose assume that for time being we are having some 17 00:00:51,800 --> 00:00:52,800 two employees. 18 00:00:54,300 --> 00:00:55,400 Right. Then, 19 00:00:56,100 --> 00:01:00,000 I want to maintain the data for these two employees, then 20 00:01:01,000 --> 00:01:02,700 before going to maintain the data first 21 00:01:02,700 --> 00:01:05,800 I will assume, I am going to create one template. So I want 22 00:01:05,800 --> 00:01:07,900 to store so and so things for employee. 23 00:01:07,900 --> 00:01:10,410 [no audio] 24 00:01:10,400 --> 00:01:16,600 Right. So then what I am doing is, 'class', simply 'emp'. 25 00:01:17,200 --> 00:01:19,400 That's it. ':', then enter. 26 00:01:20,200 --> 00:01:21,200 So I am defining 27 00:01:22,300 --> 00:01:24,200 one method to store 28 00:01:24,200 --> 00:01:27,800 the employee name, age and salary suppose. 29 00:01:27,800 --> 00:01:28,800 So let me define 30 00:01:28,800 --> 00:01:33,010 [no audio] 31 00:01:33,000 --> 00:01:38,000 as 'get_name_age_salary'. 32 00:01:38,000 --> 00:01:39,800 [no audio] 33 00:01:39,800 --> 00:01:42,200 That's it. So actually, this is a function. 34 00:01:42,200 --> 00:01:44,300 But whenever if you want to write a function inside of a 35 00:01:44,300 --> 00:01:48,700 class, you have to write by default 'self' as the key, and you 36 00:01:48,700 --> 00:01:51,600 don't need to worry about the value for 'self'. Automatically 37 00:01:51,600 --> 00:01:54,500 'self' will be replaced by the particular object. From which 38 00:01:54,500 --> 00:01:57,500 object you're calling that object will come in the place of 'self'. 39 00:01:58,100 --> 00:01:59,100 That's fine. 40 00:01:59,200 --> 00:02:02,300 Now you are expecting for this function 'name', 'age', and 'salary'. 41 00:02:02,300 --> 00:02:06,500 Let me take variables as, I mean I will pass arguments for 42 00:02:06,500 --> 00:02:09,709 this method while calling like 'name', 43 00:02:09,699 --> 00:02:12,609 'age' and 'salary'. That's it. 44 00:02:12,600 --> 00:02:18,700 Then I want to store this 'name', 'age', and 'salary' in a memory 45 00:02:18,700 --> 00:02:24,000 location. So for that you have to write 'self.name=name'. 46 00:02:24,000 --> 00:02:27,200 So guys don't get confused, 'self.name' is different, and 47 00:02:27,200 --> 00:02:28,200 'name' is different. 48 00:02:28,600 --> 00:02:33,000 It is like 'xy = y', completely they are different variables. 49 00:02:34,300 --> 00:02:39,810 Right. Then 'self.age = age'. 50 00:02:39,800 --> 00:02:42,500 So if you are getting confusion just take here arguments 51 00:02:42,500 --> 00:02:43,800 as different variables, 52 00:02:43,800 --> 00:02:48,000 I mean different names like 'n', 'a', 's', but if you take 'name', 53 00:02:48,000 --> 00:02:49,900 'age', 'salary', just somewhat meaningful 54 00:02:49,900 --> 00:02:55,010 that's why I'm taking arguments as 'name', 'age' and 'salary'. Then 55 00:02:55,000 --> 00:02:56,500 'self.salary'. 56 00:02:58,200 --> 00:03:01,800 That's it. Then I am going to define one more function just to display 57 00:03:01,800 --> 00:03:03,500 the employee details. 58 00:03:05,100 --> 00:03:10,400 Then what I can do, 'display_emp_details', or simply 59 00:03:10,400 --> 00:03:11,400 'display_details 60 00:03:11,400 --> 00:03:13,800 [no audio] 61 00:03:13,800 --> 00:03:16,800 (self)'. So actually to display employee details 62 00:03:16,800 --> 00:03:18,700 what we need? 'name', 'age', and 'salary'. 63 00:03:19,700 --> 00:03:24,300 So if you are using normal function like 'display_details', 64 00:03:24,300 --> 00:03:27,400 if it is a normal function, to get your details you need to 65 00:03:27,400 --> 00:03:32,400 pass arguments to this function, but this is a method and 66 00:03:32,400 --> 00:03:35,700 if you observe these two methods are in the same class, that's 67 00:03:35,700 --> 00:03:41,010 why whatever the variables you are having you define in your 68 00:03:41,000 --> 00:03:45,910 first method, those variables you can access in other method. 69 00:03:45,900 --> 00:03:48,800 That's why I'm not passing any arguments to 'display_details' 70 00:03:48,800 --> 00:03:50,200 method. Directly 71 00:03:50,200 --> 00:03:52,709 I can access from my previous method. 72 00:03:52,700 --> 00:03:53,500 So that's why directly 73 00:03:53,500 --> 00:03:55,000 what I am doing is, simply 'print( 74 00:03:56,500 --> 00:03:58,800 "The name is:". So simply here 75 00:03:58,800 --> 00:04:02,700 I will write 'name'. Name is nothing but 'self.name', but 76 00:04:02,700 --> 00:04:03,800 not this 'name' guys. 77 00:04:05,200 --> 00:04:07,400 This you're passing to this method while calling. 78 00:04:08,800 --> 00:04:14,100 Okay. But actual variables or attributes for your objects 79 00:04:14,100 --> 00:04:15,100 are these things. 80 00:04:16,800 --> 00:04:22,709 Then let me write "/n The age is: ", you can write anything. 81 00:04:22,700 --> 00:04:25,200 No problem. Just for your understanding 82 00:04:25,200 --> 00:04:31,700 I'm writing simple script. Then, "The salary is: ". 83 00:04:31,700 --> 00:04:34,010 [no audio] 84 00:04:34,000 --> 00:04:38,100 That's it. Let me write salary, 'self.salary'. That's it. 85 00:04:39,200 --> 00:04:41,900 Right. Then write simply 'return None'. 86 00:04:41,900 --> 00:04:44,010 [no audio] 87 00:04:44,000 --> 00:04:47,210 So I'm not expecting any return value from this method. 88 00:04:47,200 --> 00:04:51,600 So here also I'm not expecting any return value, 89 00:04:51,600 --> 00:04:54,900 that's why I'm writing simply 'return None'. That's fine. 90 00:04:54,900 --> 00:04:57,500 So guys, if you run your code as of now, you're not getting 91 00:04:57,500 --> 00:04:59,900 any output and you are not going to get any error because 92 00:04:59,900 --> 00:05:03,300 this is just a template. Templates won't execute whenever you 93 00:05:03,300 --> 00:05:06,600 run. It will execute whenever if you assign this template 94 00:05:06,600 --> 00:05:07,600 to any object. 95 00:05:08,700 --> 00:05:10,100 Right. That's fine. 96 00:05:10,700 --> 00:05:13,909 Now see that. Just assume that we are having two employees, 97 00:05:13,900 --> 00:05:15,900 say 'emp1' and 'emp2'. 98 00:05:15,900 --> 00:05:18,210 [no audio] 99 00:05:18,200 --> 00:05:19,200 Okay. 100 00:05:20,500 --> 00:05:25,200 Now I want to store the details for 'emp1' and 'emp2', 101 00:05:25,200 --> 00:05:30,100 and I want to see whenever if I need. So to store we have 102 00:05:30,100 --> 00:05:33,700 this method, and to display we have this method, second method. 103 00:05:35,100 --> 00:05:41,300 Right. So instead of 'get' let me 'assign', or yeah, no problem. 104 00:05:41,300 --> 00:05:42,810 You can take any method, right? 105 00:05:42,800 --> 00:05:43,900 So 'emp1'. 106 00:05:44,300 --> 00:05:48,900 So before going to store 'emp1' details, what you have to do? 107 00:05:48,900 --> 00:05:52,600 First of all, you need to assign this template for this object. 108 00:05:53,600 --> 00:05:58,409 Right. Then only these methods and these attributes or variables, 109 00:05:58,400 --> 00:05:59,900 you can access from 'emp1'. 110 00:06:00,700 --> 00:06:02,300 That's why, what I'm doing? First 111 00:06:02,300 --> 00:06:05,700 I am doing 'emp()', then for 'emp1()', and 'emp2()'. 112 00:06:06,800 --> 00:06:07,800 That's it. 113 00:06:09,800 --> 00:06:13,300 Right. So guys as of now you have 'emp1' and 'emp2' 114 00:06:13,300 --> 00:06:17,000 objects, but there is no information for 'emp1' 115 00:06:17,000 --> 00:06:21,000 and 'emp2'. Because, if you execute any one of the method, 116 00:06:22,500 --> 00:06:26,100 then only you're going to store your data. Suppose to store your data 117 00:06:26,100 --> 00:06:28,600 you have to execute this method, then you need to call that 118 00:06:28,600 --> 00:06:32,200 method. You know how to call a method of your class. 119 00:06:33,400 --> 00:06:37,100 Now, assume that this entire class, this template is stored 120 00:06:37,100 --> 00:06:40,300 in the name of 'emp1' and 'emp2'. So whenever if 121 00:06:40,300 --> 00:06:46,700 you call from 'emp1', 'emp1.get_name_age_salary'. 122 00:06:46,700 --> 00:06:50,000 Let's say I am giving as suppose 123 00:06:51,000 --> 00:06:52,900 'name', anything like John, 124 00:06:52,900 --> 00:06:54,700 [no audio] 125 00:06:54,700 --> 00:06:56,400 'age' suppose 34, 126 00:06:57,700 --> 00:07:00,400 then I am giving 'salary' as something like, 127 00:07:00,400 --> 00:07:02,800 [no audio] 128 00:07:02,800 --> 00:07:07,200 just assume it may be 45000 per month. Just assume that. 129 00:07:08,600 --> 00:07:09,700 Right. Fine. 130 00:07:10,900 --> 00:07:15,900 Now, the same way I want to store my data, my 'emp2' data, then 131 00:07:18,800 --> 00:07:19,800 just write 132 00:07:19,800 --> 00:07:33,409 [no audio] 133 00:07:33,400 --> 00:07:35,300 That's it. Okay. 134 00:07:35,600 --> 00:07:38,900 Now if I execute, while running your program somewhere in 135 00:07:38,900 --> 00:07:42,600 memory location two memory blocks will be created. One memory 136 00:07:42,600 --> 00:07:46,500 block for 'emp1' and second memory is for 'emp2'. 137 00:07:47,600 --> 00:07:53,700 Right. And see before calling your 'display' if I write 'dir(emp1)' 138 00:07:55,000 --> 00:07:56,800 See the result, what you are getting. 139 00:07:56,800 --> 00:07:59,510 [no audio] 140 00:07:59,500 --> 00:08:02,500 Basically for 'emp1', what are the information 141 00:08:02,500 --> 00:08:04,400 you are having? 'name', 142 00:08:05,000 --> 00:08:09,700 I mean this method and variables, right, and one more method 143 00:08:09,700 --> 00:08:11,200 here. Now see the output. 144 00:08:11,200 --> 00:08:13,300 Anyway, these are the default values. 145 00:08:13,300 --> 00:08:18,800 Other than that, see that. 'age' is there, 'name' is there, 'salary' 146 00:08:18,800 --> 00:08:24,500 is there. So 'emp1.age', 'emp1.name', 'emp1.salary'. 147 00:08:24,500 --> 00:08:27,100 The same way you can use, this is the method, 148 00:08:27,100 --> 00:08:28,909 these two are the methods. We know 149 00:08:28,900 --> 00:08:30,710 that. By observing here 150 00:08:30,700 --> 00:08:32,700 we can understand that these two are methods. 151 00:08:32,700 --> 00:08:34,700 So 'emp1.display_details()'. 152 00:08:34,700 --> 00:08:37,299 'emp1.get_name_age_salary'. 153 00:08:37,900 --> 00:08:41,909 But while calling if you need arguments, you need to pass. 154 00:08:41,900 --> 00:08:44,000 The same way you can also run this for 155 00:08:45,600 --> 00:08:46,600 'emp2'. 156 00:08:46,600 --> 00:08:49,799 [no audio] 157 00:08:49,799 --> 00:08:51,799 Same information is there for 'emp2' also 158 00:08:51,799 --> 00:08:52,900 but the values are different. 159 00:08:53,799 --> 00:08:54,799 That's it. 160 00:08:55,600 --> 00:09:01,000 Now fine. Just observe this guys. While calling from your 14th line 161 00:09:01,000 --> 00:09:03,800 or 'emp1.get_name_age_salary 162 00:09:04,400 --> 00:09:07,100 ("John", 34, 45000)', values 163 00:09:07,100 --> 00:09:10,900 will be assigned to respectively 'name', 'age' and 'salary'. Then 164 00:09:10,900 --> 00:09:11,900 what about 'self'? 165 00:09:13,400 --> 00:09:16,800 'self' by default from which object you are calling, that object 166 00:09:16,800 --> 00:09:18,410 'name' will be stored in 'self'. 167 00:09:18,400 --> 00:09:20,600 That's why in memory it is going to create like 168 00:09:20,600 --> 00:09:23,400 'emp1.name' not 'self.name'. 169 00:09:24,400 --> 00:09:28,300 Okay. For our purpose, for dynamic purpose we are writing 'self', 170 00:09:29,500 --> 00:09:33,300 but while storing your values, your variables in memory location 171 00:09:33,300 --> 00:09:36,600 they are going to store in the respective by using 'emp1', 172 00:09:36,600 --> 00:09:39,900 'emp1.name', 'emp1.age', 'emp1.salary'. 173 00:09:40,800 --> 00:09:43,700 That's it. And one more thing, whenever you are accessing 174 00:09:43,700 --> 00:09:46,500 your variables inside of a class, always you have to take 175 00:09:46,500 --> 00:09:49,800 'self.name', 'self.age', 'self.salary', like that. 176 00:09:51,500 --> 00:09:53,510 But for same 'emp1' 177 00:09:53,500 --> 00:09:57,400 if you want to access your variables, attributes outside of 178 00:09:57,400 --> 00:10:01,810 a class, outside of a class, then you have to access with 179 00:10:01,800 --> 00:10:06,300 'emp1.' not 'self.'. Be clear. Outside you have to 180 00:10:06,300 --> 00:10:09,200 access with the 'emp1.'. Suppose 181 00:10:09,200 --> 00:10:11,900 I want to display 'age'. See the result what you are getting. 182 00:10:11,900 --> 00:10:13,200 34. That's fine. 183 00:10:14,700 --> 00:10:18,000 And if you observe even method we are also calling as 184 00:10:18,000 --> 00:10:21,300 'emp1.'. Suppose if I want to call 185 00:10:21,300 --> 00:10:26,600 'display' method, how can I call? 'emp1.display_details'. That's it. 186 00:10:27,300 --> 00:10:32,600 If you observe 'display_details' is not requiring any arguments, 187 00:10:32,600 --> 00:10:35,010 it is not taking any arguments except 'self'. 188 00:10:35,000 --> 00:10:38,400 Anyway, 'self' is going to store with the help of 'emp1'. 189 00:10:39,500 --> 00:10:43,700 'emp1.name' will store into 'self', that's why we are passing 190 00:10:43,700 --> 00:10:45,600 correct arguments while calling 'display' method. 191 00:10:45,600 --> 00:10:47,100 Now just observe the result. 192 00:10:47,100 --> 00:10:49,610 [no audio] 193 00:10:49,600 --> 00:10:53,600 And one more thing, you are calling your method outside of a class. 194 00:10:55,200 --> 00:10:59,810 Suppose I want to display my details after assigning the 195 00:10:59,800 --> 00:11:02,000 data to your 'self.name', 'age' and 'salary', 196 00:11:02,000 --> 00:11:05,700 then you have to call this method inside of this first method. 197 00:11:05,700 --> 00:11:09,300 So whenever if you want to call your method inside of a method 198 00:11:09,300 --> 00:11:13,100 then you have to write 'self.', method name. 199 00:11:13,100 --> 00:11:15,510 [no audio] 200 00:11:15,500 --> 00:11:18,600 So 'self' means outside you can assume this is like 'emp1', 201 00:11:18,400 --> 00:11:20,700 but inside of a class if you want to call and if you 202 00:11:20,700 --> 00:11:23,500 want to execute any method you have to write 'self.'. Now, 203 00:11:23,500 --> 00:11:26,300 let me comment this and see the result. You're going to get, 204 00:11:26,300 --> 00:11:30,100 'display_details' for two employees. See that. 205 00:11:31,200 --> 00:11:33,900 First you are assigning. Because of third fourth and fifth 206 00:11:33,900 --> 00:11:36,700 lines, you are assigning your values for your attributes 207 00:11:36,700 --> 00:11:39,800 or variables. Then immediately you're calling the respective 208 00:11:39,800 --> 00:11:42,000 object 'display_details' method. 209 00:11:42,000 --> 00:11:44,800 That's why you're going to get the same values in the output. That's it. 210 00:11:46,000 --> 00:11:48,100 You are assigning, and then you are displaying. That's 211 00:11:48,100 --> 00:11:49,800 it. So be clear. 212 00:11:49,800 --> 00:11:53,200 If you want to execute a method inside of a class, you have 213 00:11:53,200 --> 00:11:55,500 to write 'self.', but outside of a class 214 00:11:55,500 --> 00:11:57,800 you have to write your object name, '.', that method name. 215 00:11:57,800 --> 00:11:59,800 [no audio] 216 00:11:59,800 --> 00:12:03,000 That's fine. And if you observe this entire program, you are having 217 00:12:03,000 --> 00:12:04,700 these are like attributes. 218 00:12:04,700 --> 00:12:07,310 [no audio] 219 00:12:07,300 --> 00:12:11,600 Right. And these attributes, these attributes are specific for 220 00:12:11,600 --> 00:12:14,600 particular object because we are writing 'self.'. 'self' is 221 00:12:14,600 --> 00:12:15,910 nothing but object name. 222 00:12:15,900 --> 00:12:19,300 So these attributes are related to your object. 223 00:12:20,700 --> 00:12:22,800 That's fine. Now, 224 00:12:24,100 --> 00:12:30,400 I have a small requirement. After creation of, after creation 225 00:12:30,400 --> 00:12:31,800 of your objects. 226 00:12:32,200 --> 00:12:37,300 I need to find at last how many employee objects have been 227 00:12:37,300 --> 00:12:39,100 created using this template. 228 00:12:39,100 --> 00:12:41,000 [no audio] 229 00:12:41,000 --> 00:12:45,000 How many employee objects have been created by using this 230 00:12:45,000 --> 00:12:46,900 template. I have to know that. Count 231 00:12:46,900 --> 00:12:49,200 I need to find out. See what I am doing is, 232 00:12:50,800 --> 00:12:54,200 I am writing 'count'. 'count =', initially 0. 233 00:12:54,200 --> 00:12:56,210 [no audio] 234 00:12:56,200 --> 00:13:00,900 So whenever if I create 'emp1', at that time I need 235 00:13:00,900 --> 00:13:04,200 to increase this value, I need to increase this value. 236 00:13:04,200 --> 00:13:06,300 This value is not related with your object. 237 00:13:07,300 --> 00:13:09,600 This is related with your template, your class. 238 00:13:09,600 --> 00:13:12,600 This is class variable. See that. If I want to access that 239 00:13:12,600 --> 00:13:14,400 variable from outside of your class 240 00:13:14,400 --> 00:13:16,600 I need to access with the 'emp.count'. 241 00:13:16,600 --> 00:13:19,100 What is 'emp' here? Class name. 242 00:13:20,300 --> 00:13:22,100 0, you're getting. Let me comment. 243 00:13:22,100 --> 00:13:23,960 [no audio] 244 00:13:23,950 --> 00:13:27,600 By default we are calling 'display_details', right. Now 245 00:13:27,600 --> 00:13:28,900 just observe the output. 246 00:13:28,900 --> 00:13:31,310 [no audio] 247 00:13:31,300 --> 00:13:32,300 You're getting 0. 248 00:13:32,800 --> 00:13:36,300 Right. I can increase this value at any time, may be inside of a 249 00:13:36,300 --> 00:13:40,210 class, inside of a method, or outside of a class. See, 250 00:13:40,200 --> 00:13:46,900 I am doing 'emp.count = emp.count + 1'. 251 00:13:48,400 --> 00:13:50,900 So after that, I am printing my 'emp.count'. 252 00:13:50,900 --> 00:13:53,310 [no audio] 253 00:13:53,300 --> 00:13:54,510 That's it. 254 00:13:54,500 --> 00:13:57,700 Now this variable, if you define any variable outside of your 255 00:13:57,700 --> 00:14:02,600 methods without 'self', then that is for your template or 256 00:14:02,600 --> 00:14:04,300 for your class attribute. 257 00:14:05,800 --> 00:14:07,300 That is a class attribute. 258 00:14:08,300 --> 00:14:11,800 Now, what I am doing is, I am taking the help of this variable 259 00:14:11,800 --> 00:14:15,300 and whenever if I create an object at that time I will increase this value. 260 00:14:15,300 --> 00:14:19,710 I can increase either inside of a class or inside of a method 261 00:14:19,700 --> 00:14:23,300 or outside of a class. See how I am going to do that. 262 00:14:25,000 --> 00:14:28,210 See whenever if I create these values. 263 00:14:27,600 --> 00:14:30,100 Right. That means you're creating an object, right? 264 00:14:30,100 --> 00:14:32,400 So in this I'm going to create one more method. 265 00:14:32,400 --> 00:14:33,810 You can create any method. 266 00:14:33,800 --> 00:14:36,200 I mean like 'increase_count', 'increase_ 267 00:14:36,200 --> 00:14:39,410 [no audio] 268 00:14:39,400 --> 00:14:43,400 count_for_employee', not for your object. 269 00:14:43,400 --> 00:14:45,410 [no audio] 270 00:14:45,400 --> 00:14:49,800 But method is we are writing inside of your class, right. See 271 00:14:49,800 --> 00:14:52,200 what I am doing is, simply I am writing 'emp'. 272 00:14:52,200 --> 00:14:57,000 this is the class name, then 'count = emp.count + 1'. 273 00:14:58,500 --> 00:15:00,600 Of course, you can also write your shortcut for your 274 00:15:00,600 --> 00:15:04,800 arithmetic operation. Then simply 'return None'. That's it. 275 00:15:04,800 --> 00:15:11,510 [no audio] 276 00:15:11,500 --> 00:15:14,910 See, but I need to manually run this, 277 00:15:14,900 --> 00:15:18,110 I mean I execute this method whenever if I create an object, 278 00:15:18,100 --> 00:15:23,000 so I mean after giving your 'name', 'age', and 'salary' for any employee, 279 00:15:23,000 --> 00:15:27,700 after that I need to call 'emp1.increase_count_for_emp()', 280 00:15:27,700 --> 00:15:29,810 [no audio] 281 00:15:29,800 --> 00:15:36,000 then 'emp2.increase_count_for_emp()'. 282 00:15:37,000 --> 00:15:39,100 That's it. Now see the result. 283 00:15:39,100 --> 00:15:40,900 Yeah, let me print so that you can understand. 284 00:15:40,900 --> 00:15:43,910 [no audio] 285 00:15:43,900 --> 00:15:48,100 So what is the variable? 'emp.count'. See the result. 286 00:15:48,100 --> 00:15:50,500 Two variables have been, sorry two objects have been created 287 00:15:50,500 --> 00:15:51,500 by using this template. 288 00:15:53,000 --> 00:15:56,300 Try to understand this variable, normal variable, right, like 289 00:15:56,300 --> 00:16:00,800 'x =', something. 'count = 0'. Now, if you define 290 00:16:00,800 --> 00:16:04,410 the variable immediately after writing your class, class name, 291 00:16:04,400 --> 00:16:07,600 if you define any variable, right, that variable is related 292 00:16:07,600 --> 00:16:08,600 for your class. 293 00:16:08,800 --> 00:16:10,500 So this is called class attribute. 294 00:16:11,500 --> 00:16:15,600 So why we need class attribute means, how many, suppose 295 00:16:15,600 --> 00:16:16,600 one of the example I am giving 296 00:16:16,600 --> 00:16:19,000 but you can define any number of variables based 297 00:16:19,000 --> 00:16:20,000 on your requirement. 298 00:16:20,300 --> 00:16:23,400 The very simple thing I am giving is, from the template how many 299 00:16:23,400 --> 00:16:24,900 objects has been created? 300 00:16:26,200 --> 00:16:29,300 To count that I am defining one variable, one attribute called 301 00:16:29,300 --> 00:16:30,500 'count'. That's it. 302 00:16:31,600 --> 00:16:34,700 So if you don't want to call externally your increase count 303 00:16:34,700 --> 00:16:38,100 for employee just comment these two methods here. 304 00:16:38,700 --> 00:16:41,600 So whenever if you create your variables immediately call 305 00:16:41,600 --> 00:16:44,500 'self.increase_count_for_emp'. 306 00:16:45,400 --> 00:16:48,800 That's it. Now see the result. Same output, right. 2, you're getting. 307 00:16:51,300 --> 00:16:56,700 Okay. So guys, this is all about simply class and object attributes. 308 00:16:57,700 --> 00:17:03,000 Be clear. These are class object attributes, and this is for your class 309 00:17:03,000 --> 00:17:09,500 attribute. And remember that class attributes we have to call 310 00:17:09,500 --> 00:17:14,800 or we have to save like 'self.', your variable name. Even 311 00:17:14,800 --> 00:17:18,098 while displaying that we have to take 'self.'. That is only 312 00:17:18,098 --> 00:17:19,300 inside of a class. 313 00:17:20,098 --> 00:17:23,598 But if you come outside, then you have to take instead of 314 00:17:23,500 --> 00:17:28,500 'self', particular object name, 'emp1.name', 'emp2.name', 315 00:17:28,500 --> 00:17:32,000 something like that. But for class variable, this 316 00:17:32,000 --> 00:17:34,500 is class variable or class attribute, 'count'. 317 00:17:35,099 --> 00:17:38,800 So either inside of a method, inside of a class, or outside 318 00:17:38,800 --> 00:17:42,000 of a class, you can always access with the help of 'emp', 319 00:17:42,099 --> 00:17:45,400 I mean template, class name, '.', your attribute. 320 00:17:45,400 --> 00:17:47,810 [no audio] 321 00:17:47,800 --> 00:17:51,599 Be clear. For 'emp' object inside 'self', outside 'emp1', 322 00:17:52,300 --> 00:17:57,200 or 'emp2', outside, inside 'self.'. But whereas 323 00:17:57,200 --> 00:18:00,300 for class variables, attributes wherever you go, I mean 324 00:18:00,500 --> 00:18:05,300 in any line in your program, you have to take always 'emp.count', 325 00:18:05,300 --> 00:18:08,200 I mean your class name, '.', that variable. That's it. 326 00:18:09,100 --> 00:18:12,100 Okay. Okay guys, thank you for watching this simple video. 327 00:18:12,100 --> 00:18:14,647 [no audio]