WEBVTT 1 00:00:00.170 --> 00:00:01.590 Hi and welcome back. 2 00:00:01.590 --> 00:00:05.250 In this video we're talking about dictionaries and objects. 3 00:00:05.250 --> 00:00:07.720 And we're going to introduce this concept` 4 00:00:07.720 --> 00:00:10.430 of object-oriented programming. 5 00:00:10.430 --> 00:00:13.050 Now the way I've got planned to introduce this to you, 6 00:00:13.050 --> 00:00:14.230 I'm pretty chuffed with. 7 00:00:14.230 --> 00:00:16.560 I think this is gonna be quite understandable, 8 00:00:16.560 --> 00:00:19.650 so let's get on it and see how it turns out. 9 00:00:19.650 --> 00:00:22.840 We've looked at dictionaries as things that we can use 10 00:00:22.840 --> 00:00:26.563 to represent things in our programme. 11 00:00:27.680 --> 00:00:29.880 For example, we can have a dictionary 12 00:00:29.880 --> 00:00:31.640 that represents a student. 13 00:00:31.640 --> 00:00:34.608 We can say my student is equal to this in your dictionary. 14 00:00:34.608 --> 00:00:36.220 Has a name 15 00:00:38.440 --> 00:00:40.363 and potentially has some grades, 16 00:00:42.910 --> 00:00:43.910 something like that. 17 00:00:44.800 --> 00:00:49.170 Now in our programme, this dictionary represents 18 00:00:49.170 --> 00:00:51.800 what we think of a student. 19 00:00:51.800 --> 00:00:53.650 And another part of our programme, 20 00:00:53.650 --> 00:00:55.810 we may do things like print out the student's name 21 00:00:55.810 --> 00:00:58.640 or calculate the average grade of the student 22 00:00:58.640 --> 00:01:03.210 and use this dictionary as though it was a student. 23 00:01:03.210 --> 00:01:05.510 Even though of course we know that real students 24 00:01:05.510 --> 00:01:09.180 in the real world have a lot more properties like an address 25 00:01:09.180 --> 00:01:13.040 and, you know, a family and things like that, 26 00:01:13.040 --> 00:01:16.210 in our programme, we don't care about those other properties. 27 00:01:16.210 --> 00:01:19.640 We only care about the properties that we're going to use. 28 00:01:19.640 --> 00:01:23.060 So in our programme, this dictionary can represent a student. 29 00:01:23.060 --> 00:01:26.000 And if we expand our programme and we need more properties, 30 00:01:26.000 --> 00:01:27.610 we can always modify the structure 31 00:01:27.610 --> 00:01:29.663 of this dictionary and add them in. 32 00:01:31.520 --> 00:01:33.840 And this concept of having something 33 00:01:33.840 --> 00:01:37.210 that represents a real-world entity is pretty powerful 34 00:01:37.210 --> 00:01:39.480 in programming and it allows us to start thinking 35 00:01:39.480 --> 00:01:41.812 of our programmes in terms of what they do 36 00:01:41.812 --> 00:01:44.080 as opposed to how they do it. 37 00:01:44.080 --> 00:01:46.680 Let's move on and assume we want to calculate 38 00:01:46.680 --> 00:01:48.930 the average grade of this student 39 00:01:48.930 --> 00:01:50.410 so that we can, for example, put it 40 00:01:50.410 --> 00:01:52.060 in some sort of report somewhere. 41 00:01:52.910 --> 00:01:55.510 I think you can already calculate the average grade 42 00:01:55.510 --> 00:01:57.650 of this student quite easily, so I'm going to ask you 43 00:01:57.650 --> 00:02:00.040 to pause the video and give this a go. 44 00:02:00.040 --> 00:02:02.517 Try to implement a function that will return 45 00:02:02.517 --> 00:02:05.850 the average grade of this student. 46 00:02:05.850 --> 00:02:06.920 I hope you got that. 47 00:02:06.920 --> 00:02:09.240 What we're going to do is we're going to define 48 00:02:09.240 --> 00:02:11.670 an average grade function. 49 00:02:11.670 --> 00:02:12.890 It's going to take one parameter 50 00:02:12.890 --> 00:02:15.480 that is going to be the student, 51 00:02:15.480 --> 00:02:17.460 then a colon at the end, of course, 52 00:02:17.460 --> 00:02:18.982 and all it's going to do is it's going to add up 53 00:02:18.982 --> 00:02:22.410 the grades that we're gonna do with the sum 54 00:02:22.410 --> 00:02:26.960 of the student grades and it's going to divide that sum 55 00:02:26.960 --> 00:02:30.370 by the length of the student grades. 56 00:02:30.370 --> 00:02:32.210 The length, again, is the count 57 00:02:32.210 --> 00:02:35.510 of how many there are, and there are four in this case. 58 00:02:35.510 --> 00:02:38.983 And naturally, it's going to return that calculation. 59 00:02:39.820 --> 00:02:42.120 So now if we wanted to print out the average 60 00:02:44.060 --> 00:02:46.300 of my student, we can do that. 61 00:02:46.300 --> 00:02:47.530 Again, all we're doing here is 62 00:02:47.530 --> 00:02:49.790 we are evaluating my student. 63 00:02:49.790 --> 00:02:51.240 It's just a dictionary. 64 00:02:51.240 --> 00:02:52.830 We're calling the average grade function 65 00:02:52.830 --> 00:02:53.930 with that as an argument. 66 00:02:53.930 --> 00:02:56.180 So the value of my student, this dictionary 67 00:02:57.020 --> 00:02:59.993 will then go into the student parameter. 68 00:03:01.140 --> 00:03:03.730 And that's going to return these calculations here. 69 00:03:03.730 --> 00:03:04.980 And then we're going to print that out. 70 00:03:04.980 --> 00:03:05.853 So let's run it. 71 00:03:07.070 --> 00:03:08.930 As you can see, we get eighty-six point seventy-five, 72 00:03:08.930 --> 00:03:10.180 which sounds about right. 73 00:03:11.760 --> 00:03:14.580 However, and here comes the interesting bit, 74 00:03:14.580 --> 00:03:18.130 there is a flaw with this entire programme. 75 00:03:18.130 --> 00:03:19.640 I'm going to just delete that. 76 00:03:19.640 --> 00:03:23.380 The flaw is not in the code. The code is totally fine. 77 00:03:23.380 --> 00:03:24.460 It does what it's meant to do; 78 00:03:24.460 --> 00:03:26.150 it calculates the average grade 79 00:03:26.150 --> 00:03:28.660 the student as a dictionary is defined up there. 80 00:03:28.660 --> 00:03:30.940 All the code works and it prints out 81 00:03:30.940 --> 00:03:32.840 or it gives us the value that we want. 82 00:03:33.930 --> 00:03:37.490 The flaw is in its design. 83 00:03:37.490 --> 00:03:41.370 Not in user interface design, but in software design. 84 00:03:41.370 --> 00:03:43.940 This is a concept, and I hope a topic, 85 00:03:43.940 --> 00:03:46.070 that the majority of coding tutorials out there 86 00:03:46.070 --> 00:03:48.340 just completely skip over. 87 00:03:48.340 --> 00:03:49.510 I think it's pretty important and I think 88 00:03:49.510 --> 00:03:52.580 it's a good way to explain an object-oriented programme. 89 00:03:52.580 --> 00:03:55.890 The flaw in the software design is that 90 00:03:55.890 --> 00:03:59.450 these two functions are 91 00:03:59.450 --> 00:04:01.790 essentially unrelated. 92 00:04:01.790 --> 00:04:04.760 Even though they are very closely 93 00:04:04.760 --> 00:04:06.870 or seemingly closely related 94 00:04:06.870 --> 00:04:08.693 they are essentially disjoined. 95 00:04:09.800 --> 00:04:10.670 And what I mean to say by that is 96 00:04:10.670 --> 00:04:14.690 you've got this function and in a large programme, 97 00:04:14.690 --> 00:04:16.550 potentially you could have a function somewhere 98 00:04:16.550 --> 00:04:18.730 in a totally different file altogether 99 00:04:18.730 --> 00:04:21.260 that gives you the average grade. 100 00:04:21.260 --> 00:04:22.320 And in a different file altogether, 101 00:04:22.320 --> 00:04:23.550 you could have this student. 102 00:04:23.550 --> 00:04:24.830 So these could be in completely 103 00:04:24.830 --> 00:04:28.650 different places physically, in a large project. 104 00:04:28.650 --> 00:04:33.360 However, we say that these two things are tightly coupled 105 00:04:34.310 --> 00:04:38.490 in that the average grade function requires 106 00:04:38.490 --> 00:04:42.150 that the parameter be a dictionary 107 00:04:42.150 --> 00:04:43.850 and it requires that the parameter 108 00:04:43.850 --> 00:04:46.610 have the key grades in it. 109 00:04:46.610 --> 00:04:49.080 In order to be able to fulfil its purpose 110 00:04:49.080 --> 00:04:52.870 it's totally fine for a function to have those requirements, 111 00:04:52.870 --> 00:04:55.430 but not when it's also possible for the function 112 00:04:55.430 --> 00:04:57.540 to be in a completely different place. 113 00:04:57.540 --> 00:04:58.530 Because then, let's say you wanted 114 00:04:58.530 --> 00:05:02.390 to change grades or results, for example. 115 00:05:02.390 --> 00:05:05.040 You'd have a mayhem if you've got functions 116 00:05:05.040 --> 00:05:07.380 all over the place that rely on the student 117 00:05:07.380 --> 00:05:10.003 to have a grades key but now you changed it. 118 00:05:11.530 --> 00:05:14.930 So this is the flaw in the design of this programme. 119 00:05:14.930 --> 00:05:18.730 We've got a function that is not 120 00:05:18.730 --> 00:05:21.060 living with the student, 121 00:05:21.060 --> 00:05:23.900 but is tightly coupled to that student. 122 00:05:23.900 --> 00:05:25.663 To this dictionary structure. 123 00:05:27.240 --> 00:05:29.140 So it would be great if we could 124 00:05:29.140 --> 00:05:32.613 have our function living inside the dictionary. 125 00:05:34.080 --> 00:05:36.280 So that it lives in the same place 126 00:05:36.280 --> 00:05:38.790 as the data that it acts on. 127 00:05:38.790 --> 00:05:40.200 Something like this. 128 00:05:40.200 --> 00:05:43.341 Let's say we add a new key here that's the average 129 00:05:43.341 --> 00:05:47.183 and this is like something that calculates average. 130 00:05:48.310 --> 00:05:50.080 This could be a function that calculates 131 00:05:50.080 --> 00:05:55.080 the average of a student. Of this student, specifically. 132 00:05:55.640 --> 00:05:57.940 So, currently, with these grades, 133 00:05:57.940 --> 00:06:00.800 this should be eighty-six point seventy-five. 134 00:06:00.800 --> 00:06:03.210 But, of course, if we add another grade, 135 00:06:03.210 --> 00:06:05.500 say, one hundred, this should go up to like, 136 00:06:05.500 --> 00:06:06.593 ninety, or something. 137 00:06:07.950 --> 00:06:12.860 This value here must be a function in order 138 00:06:12.860 --> 00:06:14.710 that it can be recalculated every time 139 00:06:14.710 --> 00:06:15.963 that the grades change. 140 00:06:18.330 --> 00:06:23.330 However, we cannot do that with a dictionary. 141 00:06:23.390 --> 00:06:27.380 A dictionary will not allow us to put a function here 142 00:06:27.380 --> 00:06:30.883 that acts on the data inside that same dictionary. 143 00:06:32.300 --> 00:06:33.523 It's just not possible. 144 00:06:35.890 --> 00:06:37.400 Sorry. 145 00:06:37.400 --> 00:06:40.950 So, we must use objects for this, 146 00:06:40.950 --> 00:06:43.600 because the object is the natural progression 147 00:06:43.600 --> 00:06:48.110 in this dictionary usefulness thing where it 148 00:06:48.110 --> 00:06:51.763 will allow us to act on the data that the object holds. 149 00:06:53.340 --> 00:06:55.820 So we can begin the thinking of objects just 150 00:06:55.820 --> 00:07:00.770 as a starting point of a thing that holds data, 151 00:07:00.770 --> 00:07:02.710 in this case name and grades, and it can 152 00:07:02.710 --> 00:07:06.780 also hold actions to do with that data. 153 00:07:06.780 --> 00:07:08.763 In this case, calculating the average. 154 00:07:12.060 --> 00:07:13.130 So, I'm actually, sorry, 155 00:07:13.130 --> 00:07:14.780 I'm going to keep that here for 156 00:07:14.780 --> 00:07:17.437 as we implement our object definition, 157 00:07:17.437 --> 00:07:19.293 we're going to refer back to it. 158 00:07:20.850 --> 00:07:22.730 So, what I'm going to do now, now that we know 159 00:07:22.730 --> 00:07:27.290 that an object stores data and actions to do with that data, 160 00:07:27.290 --> 00:07:30.440 is I'm going to define that object 161 00:07:31.870 --> 00:07:34.760 and this is going to be quite confusing to begin with, 162 00:07:34.760 --> 00:07:38.150 but I want us to stick to it. 163 00:07:38.150 --> 00:07:39.860 We're going to define the objects, 164 00:07:39.860 --> 00:07:41.450 then we're going to create the objects, 165 00:07:41.450 --> 00:07:43.390 those are two distinct steps, 166 00:07:43.390 --> 00:07:45.860 then we're going to explain exactly what's going on. 167 00:07:45.860 --> 00:07:48.490 What I want you to understand in terms of these objects 168 00:07:48.490 --> 00:07:52.550 is that they are just things that store data. 169 00:07:52.550 --> 00:07:55.360 Data can be a name, the grades, 170 00:07:55.360 --> 00:07:58.410 and it can also store these actions. 171 00:07:58.410 --> 00:08:01.483 So, let's start by defining what an object looks like. 172 00:08:02.630 --> 00:08:06.020 And we do that with a class. 173 00:08:06.020 --> 00:08:07.470 Okay, the class is for something 174 00:08:07.470 --> 00:08:10.143 that defines what the objects are. 175 00:08:11.720 --> 00:08:13.860 Inside the class. So, we've got the keyword class, 176 00:08:13.860 --> 00:08:15.160 then we got the name of the class. 177 00:08:15.160 --> 00:08:16.120 And normally in python they 178 00:08:16.120 --> 00:08:18.290 start with an uppercase letter. 179 00:08:18.290 --> 00:08:20.220 And then we've got a colon. Now we know 180 00:08:20.220 --> 00:08:23.720 that after a colon, things must be indented more. 181 00:08:23.720 --> 00:08:26.500 And as you can see, repl.it already suggests 182 00:08:26.500 --> 00:08:28.233 that we put four spaces in front. 183 00:08:30.190 --> 00:08:34.320 Now, inside this class, indented is four spaces. 184 00:08:34.320 --> 00:08:37.103 We're going to define two functions. 185 00:08:38.530 --> 00:08:39.908 And this is pretty weird, because so far we've 186 00:08:39.908 --> 00:08:42.550 been defining functions and in the top level 187 00:08:42.550 --> 00:08:45.400 of indentation that's at the very left of the page. 188 00:08:45.400 --> 00:08:48.060 Now, we're going to define them inside the class. 189 00:08:48.060 --> 00:08:49.920 And that's going to mean that the class 190 00:08:49.920 --> 00:08:52.780 is going to contain these functions. Okay. 191 00:08:52.780 --> 00:08:54.900 Let's start by defining the function, 192 00:08:54.900 --> 00:08:57.450 which is a special function called underscore underscore, 193 00:08:57.450 --> 00:09:00.593 that's two separate underscores, init underscore underscore. 194 00:09:01.660 --> 00:09:04.650 In python, these functions with two underscores 195 00:09:04.650 --> 00:09:05.990 in front and two underscores at the back, 196 00:09:05.990 --> 00:09:07.350 they are special functions 197 00:09:07.350 --> 00:09:09.060 and they're called dunder functions. 198 00:09:09.060 --> 00:09:10.920 So this would be a dunder init. 199 00:09:10.920 --> 00:09:12.583 Dunder for double underscore. 200 00:09:13.570 --> 00:09:16.300 This init function is going to take three parameters. 201 00:09:16.300 --> 00:09:18.950 The first one is self. The next one is going 202 00:09:18.950 --> 00:09:19.920 to be new name, and the next one 203 00:09:19.920 --> 00:09:21.270 is going to be new grade. 204 00:09:21.270 --> 00:09:23.660 These parameters can be called anything you want. 205 00:09:23.660 --> 00:09:26.570 I'm picking self for a particular reason, 206 00:09:26.570 --> 00:09:28.830 and these can be anything, but these are going 207 00:09:28.830 --> 00:09:30.860 to be the name and the grade that we're 208 00:09:30.860 --> 00:09:32.310 going to store in our object. 209 00:09:33.220 --> 00:09:34.780 And inside it we're going to say self dot name. 210 00:09:34.780 --> 00:09:36.890 Whoa. Completely wrong there. 211 00:09:36.890 --> 00:09:40.120 Self dot name equals new name. 212 00:09:40.120 --> 00:09:42.800 And self dot grades equals new grades. 213 00:09:42.800 --> 00:09:45.583 And I'm gonna make sure to make it new grades. 214 00:09:47.250 --> 00:09:49.853 Okay. Moving on to the second function. 215 00:09:49.853 --> 00:09:52.000 It's going to be an average grade function, 216 00:09:52.000 --> 00:09:54.620 pretty much like the one we've got here. 217 00:09:54.620 --> 00:09:56.520 I'm going to call it average and it's going 218 00:09:56.520 --> 00:09:58.693 to take a single parameter called self. 219 00:09:59.550 --> 00:10:02.480 Then again the colon and then what it's gonna return 220 00:10:02.480 --> 00:10:05.670 is the sum of self dot grades divided 221 00:10:05.670 --> 00:10:07.725 by the length of self dot grades. 222 00:10:07.725 --> 00:10:10.130 I appreciate this is just me typing 223 00:10:10.130 --> 00:10:11.980 and you watching. 224 00:10:11.980 --> 00:10:15.030 And now let's begin to explain exactly 225 00:10:15.030 --> 00:10:16.710 what is going on here. 226 00:10:16.710 --> 00:10:17.960 But before we can do that, 227 00:10:17.960 --> 00:10:20.770 before we can explain this scary syntax here, 228 00:10:20.770 --> 00:10:24.870 we have to define, or rather, we have to create an object. 229 00:10:24.870 --> 00:10:26.810 What we've defined here, is we've 230 00:10:26.810 --> 00:10:29.270 defined the object's structure. 231 00:10:29.270 --> 00:10:30.760 We're now going to create an object. 232 00:10:30.760 --> 00:10:34.160 So, we're going to create an object called student one. 233 00:10:34.160 --> 00:10:36.540 And the way we create a new object in python, 234 00:10:36.540 --> 00:10:40.403 is we call the class like so. 235 00:10:41.616 --> 00:10:43.230 Here we've got an opening and closing bracket there, 236 00:10:43.230 --> 00:10:47.093 and that creates a new object of type student. 237 00:10:48.240 --> 00:10:51.210 And so this student class now gets called 238 00:10:51.210 --> 00:10:53.700 using these brackets as if it were a function 239 00:10:53.700 --> 00:10:55.500 and that creates a brand new object. 240 00:10:56.490 --> 00:10:58.800 So what is an object? 241 00:10:58.800 --> 00:11:00.232 And think of an object as just 242 00:11:00.232 --> 00:11:02.820 something that can store data. 243 00:11:02.820 --> 00:11:05.803 And we're going to tell it what data to store. 244 00:11:06.780 --> 00:11:11.780 So inside this student call here, sorry about that, 245 00:11:11.780 --> 00:11:13.713 We're going to put two things. 246 00:11:14.600 --> 00:11:17.384 We're going to put Rolf Smith and we're also 247 00:11:17.384 --> 00:11:21.370 going put seventy, eighty-eight, ninety, and ninety-nine. 248 00:11:21.370 --> 00:11:24.220 Now, what's happening is, first things that's 249 00:11:24.220 --> 00:11:26.940 going to happen is this call here is 250 00:11:26.940 --> 00:11:29.400 going to create a brand new object. 251 00:11:29.400 --> 00:11:31.810 An object is a completely empty thing, 252 00:11:31.810 --> 00:11:35.790 or a more or less empty thing that allows us to store data, 253 00:11:35.790 --> 00:11:37.763 and allows us to store actions. 254 00:11:39.610 --> 00:11:41.877 When the object is created, that's created 255 00:11:41.877 --> 00:11:44.603 before we call any of these functions. 256 00:11:46.040 --> 00:11:49.850 Then it immediately calls this dunder init function. 257 00:11:49.850 --> 00:11:52.300 So the object is first created and then it immediately 258 00:11:52.300 --> 00:11:54.053 calls this dunder init function. 259 00:11:55.040 --> 00:11:58.230 The new empty object that was just created 260 00:11:59.440 --> 00:12:03.400 gets passed to self as the first parameter. 261 00:12:03.400 --> 00:12:07.940 So self is now an empty, blank object 262 00:12:07.940 --> 00:12:09.690 that has essentially nothing in it. 263 00:12:12.752 --> 00:12:13.700 And the way that python is structured, 264 00:12:13.700 --> 00:12:17.950 it then gives Rolf Smith as a new name the second parameter, 265 00:12:17.950 --> 00:12:21.733 and this list as the new grades third parameter. 266 00:12:23.570 --> 00:12:25.983 I am so confused, thinking about zero and ones here. 267 00:12:26.830 --> 00:12:31.660 So, very, very important, self is a blank object 268 00:12:31.660 --> 00:12:35.660 that was created before we called this dunder init function. 269 00:12:35.660 --> 00:12:38.150 New name is the first argument here, 270 00:12:38.150 --> 00:12:40.100 new grades is the second argument here. 271 00:12:41.280 --> 00:12:45.510 Now, we know that when we get into the first line, 272 00:12:45.510 --> 00:12:47.470 we now have these values. 273 00:12:47.470 --> 00:12:49.820 Self is a blank object, and now what we're going 274 00:12:49.820 --> 00:12:54.003 to do is use the dot to access something inside this object. 275 00:12:55.310 --> 00:12:58.183 And what we're going to access is this name thing. 276 00:12:59.210 --> 00:13:01.990 Now, let me tell you, because it's a blank object, 277 00:13:01.990 --> 00:13:05.670 it does not have anything called name inside it. 278 00:13:05.670 --> 00:13:08.830 It doesn't have a variable called name inside it. 279 00:13:08.830 --> 00:13:09.740 So what this is doing, is it's 280 00:13:09.740 --> 00:13:12.684 creating a new variable called name, 281 00:13:12.684 --> 00:13:15.940 that lives inside this blank object 282 00:13:15.940 --> 00:13:17.373 that we are calling self. 283 00:13:18.250 --> 00:13:20.820 Of course, you can call it whatever you want. 284 00:13:20.820 --> 00:13:23.070 You can call this my boject, if you want, 285 00:13:23.070 --> 00:13:25.720 or you can spell it right and call it my object. 286 00:13:25.720 --> 00:13:26.652 And that's totally okay, yeah, that's totally fine, 287 00:13:26.652 --> 00:13:30.030 you can do that if you want, 288 00:13:30.030 --> 00:13:31.920 but the convention is to call it self. 289 00:13:31.920 --> 00:13:35.630 Okay. In python, it will always be called self, 290 00:13:35.630 --> 00:13:37.490 even though you can call it whatever you want. 291 00:13:37.490 --> 00:13:40.750 So we've got this empty object, and inside of it, 292 00:13:40.750 --> 00:13:44.940 in this dot, we're defining the name variable. 293 00:13:44.940 --> 00:13:47.530 We're giving the variable the value of new name, 294 00:13:47.530 --> 00:13:48.970 which is Rolf Smith. 295 00:13:48.970 --> 00:13:51.290 So now, what was previously a completely 296 00:13:51.290 --> 00:13:53.910 blank object is no longer blank. 297 00:13:53.910 --> 00:13:56.313 It contains this name variable. 298 00:13:57.670 --> 00:13:59.260 And in the second line, we're doing the same thing. 299 00:13:59.260 --> 00:14:01.870 We're getting our now not blank object 300 00:14:01.870 --> 00:14:04.550 and we're defining a grades variable inside of it. 301 00:14:04.550 --> 00:14:07.650 And the value of that is the new grades list 302 00:14:07.650 --> 00:14:08.820 that we passed here. 303 00:14:08.820 --> 00:14:10.970 Now, before we move on to the average function, 304 00:14:10.970 --> 00:14:13.050 I want to make sure that this is clear. 305 00:14:13.050 --> 00:14:14.153 And if we print, 306 00:14:15.840 --> 00:14:17.670 student one, 307 00:14:17.670 --> 00:14:18.503 this is the object 308 00:14:18.503 --> 00:14:23.143 that we've created, dot name, we're going to get: 309 00:14:24.360 --> 00:14:26.450 Oh, we've done something incorrect here. 310 00:14:26.450 --> 00:14:30.150 Oh, yeah, sorry. We've missed something here. 311 00:14:30.150 --> 00:14:32.940 I'm just going to put none there for the time being. 312 00:14:32.940 --> 00:14:37.240 If we print out student one dot name we get Rolf Smith. 313 00:14:37.240 --> 00:14:39.930 That is what we defined up here. 314 00:14:39.930 --> 00:14:41.950 All that's happening again, student 315 00:14:41.950 --> 00:14:44.210 is creating an empty object and that's 316 00:14:44.210 --> 00:14:47.010 getting passed with a dunder init that's self. 317 00:14:47.010 --> 00:14:49.580 New name is Rolf Smith. New grades is here. 318 00:14:49.580 --> 00:14:51.540 And all we're doing is resigning new variables 319 00:14:51.540 --> 00:14:53.270 inside of self and we're giving it 320 00:14:53.270 --> 00:14:55.490 the values that we've passed it. 321 00:14:55.490 --> 00:15:00.490 So the student object is an entity that can store data. 322 00:15:00.680 --> 00:15:01.810 And the way that we store data 323 00:15:01.810 --> 00:15:04.123 in it is by using this dot name. 324 00:15:05.610 --> 00:15:09.290 However, student one knows that it 325 00:15:09.290 --> 00:15:13.320 is a student with capital S. 326 00:15:13.320 --> 00:15:14.410 And the way that we can do that is we 327 00:15:14.410 --> 00:15:16.490 can access some special property of it 328 00:15:16.490 --> 00:15:19.390 that is underscore underscore class. 329 00:15:19.390 --> 00:15:23.000 We can run that and then you see that it is class student. 330 00:15:23.000 --> 00:15:24.853 That's the type. 331 00:15:27.010 --> 00:15:30.480 So student one knows it's a student thing, 332 00:15:30.480 --> 00:15:33.843 and it has now a name and grades defined in it. 333 00:15:35.730 --> 00:15:37.943 If we were to define student two, 334 00:15:39.150 --> 00:15:40.560 make it equal to another student, 335 00:15:40.560 --> 00:15:42.930 for example, Jose and give it some grades 336 00:15:42.930 --> 00:15:45.010 of fifty, sixty, ninety-nine, and one hundred, 337 00:15:45.010 --> 00:15:47.560 I got better towards the end of the term, 338 00:15:47.560 --> 00:15:50.910 then we can print student two dot name 339 00:15:52.966 --> 00:15:54.150 and we can run that. 340 00:15:54.150 --> 00:15:56.720 And notice how it says Jose and we can print 341 00:15:58.370 --> 00:16:00.170 student one dot name 342 00:16:01.760 --> 00:16:04.040 and notice how now it says Jose and Rolf Smith. 343 00:16:04.040 --> 00:16:07.030 So these two things are completely different entities, 344 00:16:07.030 --> 00:16:09.380 completely different things. 345 00:16:09.380 --> 00:16:11.170 They both know they are students, 346 00:16:11.170 --> 00:16:13.060 and they both have this name variable 347 00:16:13.060 --> 00:16:16.150 that we've declared in here, but of course, 348 00:16:16.150 --> 00:16:19.040 if we wanted, each one could have a different property. 349 00:16:19.040 --> 00:16:22.650 Y'know, that's something you can do if you were so inclined. 350 00:16:22.650 --> 00:16:27.050 And they don't care about exactly what they are. 351 00:16:27.050 --> 00:16:29.330 All that they know is that because we've 352 00:16:29.330 --> 00:16:31.614 defined it inside of here, and we've called 353 00:16:31.614 --> 00:16:35.010 this dunder init method, they now have a name, 354 00:16:35.010 --> 00:16:37.980 the value of that name is what we passed in here. 355 00:16:37.980 --> 00:16:39.080 Nothing magical is going on. 356 00:16:39.080 --> 00:16:41.520 Just data is being passed from one place to another 357 00:16:41.520 --> 00:16:43.310 and that's really what programming is all about. 358 00:16:43.310 --> 00:16:45.800 Okay, now that we've created our object 359 00:16:45.800 --> 00:16:48.170 and we know we can create multiple objects 360 00:16:48.170 --> 00:16:51.200 and they're all just independent blank things 361 00:16:51.200 --> 00:16:53.725 that we've assigned these variables, we're ready 362 00:16:53.725 --> 00:16:58.550 to go into the next step, which is looking at this average. 363 00:16:58.550 --> 00:17:01.443 Let's do that in the very next video. I'll see you there.