1 00:00:00,000 --> 00:00:04,000 First of all, OOP is everywhere in Python. 2 00:00:04,001 --> 00:00:09,000 And to get the proof of that, let's just come back to what we have used before. 3 00:00:09,001 --> 00:00:12,770 If you remember, when we use type, for example, 4 00:00:12,782 --> 00:00:16,000 with an integer value, we get class int. 5 00:00:16,001 --> 00:00:24,000 If you do type with a string value, for example, test here, you get class str. 6 00:00:24,001 --> 00:00:27,336 You can see here the keyword class, which is 7 00:00:27,348 --> 00:00:31,000 directly related to object-oriented programming. 8 00:00:31,001 --> 00:00:34,021 I'm going to explain what a class is in just a 9 00:00:34,033 --> 00:00:37,000 moment, but for now you can see that even the 10 00:00:37,001 --> 00:00:42,000 most basic Python data types are actually using OOP. 11 00:00:42,001 --> 00:00:47,000 And this is going to be the same for most of the Python modules you are going to use. 12 00:00:47,001 --> 00:00:52,000 Now let's understand what is OOP. 13 00:00:52,001 --> 00:00:55,292 So object-oriented programming is a way of 14 00:00:55,304 --> 00:00:59,000 organizing your code into what we call classes. 15 00:00:59,001 --> 00:01:04,000 A class is basically a structure you can use to then create an object in your code. 16 00:01:04,001 --> 00:01:07,000 And what do you put inside a class? 17 00:01:07,001 --> 00:01:09,000 Well, two kinds of things. 18 00:01:09,001 --> 00:01:15,000 Variables and functions, which are of course related to the class. 19 00:01:15,001 --> 00:01:17,515 And let's see with an example actually, because 20 00:01:17,527 --> 00:01:20,000 I don't want to lose you with too much theory. 21 00:01:21,000 --> 00:01:25,000 Because I like robots and I mainly work with robotics 22 00:01:25,001 --> 00:01:28,000 programming, let's use a robot as an example. 23 00:01:28,001 --> 00:01:33,000 This will change from the classic animal or vehicle class example, 24 00:01:33,001 --> 00:01:36,592 which is always the same in every tutorial and which 25 00:01:36,604 --> 00:01:40,000 you are probably never going to use in real life. 26 00:01:40,001 --> 00:01:44,000 So let's say you want to code the behavior for a robot. 27 00:01:44,001 --> 00:01:48,000 And we are going to stay at a very high level here for the example. 28 00:01:48,001 --> 00:01:52,000 So we need to think about what kind of attributes a robot can have. 29 00:01:52,001 --> 00:01:55,895 For example, a name, a version number, the 30 00:01:55,907 --> 00:02:00,000 internal temperature of the robot, etc. etc. 31 00:02:00,001 --> 00:02:01,000 Let's keep it short. 32 00:02:01,001 --> 00:02:05,000 And then what functionalities the robot has. 33 00:02:05,001 --> 00:02:10,000 So for example, the robot can say hi with a speaker or just a string. 34 00:02:10,001 --> 00:02:12,000 It doesn't really matter here. 35 00:02:12,001 --> 00:02:15,000 Okay, so the robot can say hi and say its name. 36 00:02:16,000 --> 00:02:20,000 Then the robot can also print all its internal information, 37 00:02:20,001 --> 00:02:24,000 including the name, version number, temperature, etc. 38 00:02:24,001 --> 00:02:27,000 The robot can also initialize its hardware. 39 00:02:27,001 --> 00:02:32,000 And well, many more functionalities you can add when you need them. 40 00:02:32,001 --> 00:02:38,000 Here I keep it super basic and high level with a limited number of functionalities. 41 00:02:38,001 --> 00:02:43,000 But this is so we can focus 100% on understanding OOP. 42 00:02:43,001 --> 00:02:48,000 So we have defined attributes and functionalities for the robot. 43 00:02:48,001 --> 00:02:51,000 Now, if you want to implement that with Python code, 44 00:02:51,001 --> 00:02:55,000 you are going to create some variables for the 45 00:02:55,001 --> 00:02:57,000 first part and some functions for the second part. 46 00:02:57,001 --> 00:02:59,000 So nothing new for now. 47 00:02:59,001 --> 00:03:04,000 Well, if you create a robot class, you are simply going to group 48 00:03:04,001 --> 00:03:06,812 those variables and functions inside one 49 00:03:06,824 --> 00:03:10,000 structure that you are going to name "robot". 50 00:03:11,000 --> 00:03:15,000 And in a class, instead of using the word 51 00:03:15,001 --> 00:03:17,000 "variable", we are going to use the word "attribute". 52 00:03:17,001 --> 00:03:21,000 And instead of "function", we are going to use "method". 53 00:03:21,001 --> 00:03:26,000 This is a quite useful convention to avoid confusions. 54 00:03:26,001 --> 00:03:31,000 Okay, so for example here, the name of the robot is a class attribute 55 00:03:31,001 --> 00:03:35,000 and the init hardware function is a class method. 56 00:03:35,001 --> 00:03:40,000 Now, as you can see, creating a class doesn't add 57 00:03:40,001 --> 00:03:42,000 any functionality or special behavior to the robot. 58 00:03:42,001 --> 00:03:46,000 It's just a different way to organize and write the code. 59 00:03:46,001 --> 00:03:51,000 And speaking of writing, well, let's actually write that class with Python.