1 00:00:00,000 --> 00:00:04,380 First of all, OOP is everywhere in Python. And to 2 00:00:04,380 --> 00:00:07,140 get the proof of that, let's just come back to 3 00:00:07,140 --> 00:00:10,500 what we have used before. If you remember, when we 4 00:00:10,500 --> 00:00:14,370 use type, for example, with an integer value. We 5 00:00:14,370 --> 00:00:19,020 get class int, you can do type with string value, 6 00:00:19,020 --> 00:00:24,360 for example test here, you get class str. You can 7 00:00:24,360 --> 00:00:28,290 see here the keyword class, which is directly 8 00:00:28,320 --> 00:00:31,890 related to object oriented programming. I am going 9 00:00:31,890 --> 00:00:35,370 to explain what a class is in just a moment. But 10 00:00:35,370 --> 00:00:38,160 for now, you can see that even the most basic 11 00:00:38,190 --> 00:00:42,930 Python data types are actually using OOP. And this 12 00:00:42,930 --> 00:00:45,630 is going to be the same for most of the Python 13 00:00:45,630 --> 00:00:50,280 modules you are going to use. Now let's understand 14 00:00:50,280 --> 00:00:54,540 what is OOP. So object oriented programming is a 15 00:00:54,540 --> 00:00:57,720 way of organizing your code into what we call 16 00:00:57,750 --> 00:01:01,260 classes. A class is basically a structure you can 17 00:01:01,260 --> 00:01:04,680 use to then create an object in your code. And 18 00:01:04,680 --> 00:01:08,430 what do you put inside the class? Well, two kinds 19 00:01:08,430 --> 00:01:12,330 of things. Variables and functions, which are of 20 00:01:12,360 --> 00:01:16,050 course related to the class. And let's see with an 21 00:01:16,050 --> 00:01:18,480 example, actually, because I don't want to lose 22 00:01:18,480 --> 00:01:22,140 you with too much theory. Because I like robots, 23 00:01:22,170 --> 00:01:25,650 and I mainly work with robotics programming, let's 24 00:01:25,650 --> 00:01:29,310 use a robot as an example. This will change from 25 00:01:29,310 --> 00:01:32,670 the classic animal, or vehicle class example, 26 00:01:32,850 --> 00:01:36,120 which is always the same in every tutorial, and 27 00:01:36,120 --> 00:01:39,000 which you're probably never going to use in real 28 00:01:39,000 --> 00:01:42,510 life. So let's say you want to code the behavior 29 00:01:42,540 --> 00:01:46,170 for a robot. And we're going to stay at very high 30 00:01:46,170 --> 00:01:49,350 level here for the example. So we do think about 31 00:01:49,380 --> 00:01:53,040 what kind of attributes a robot can have. For 32 00:01:53,040 --> 00:01:56,400 example, the name, the version number, the 33 00:01:56,430 --> 00:02:00,810 internal temperature of the robot, etc, etc. Let's 34 00:02:00,810 --> 00:02:04,620 keep it short. And then what functionalities the 35 00:02:04,620 --> 00:02:08,280 robot has. So for example, the robot can say hi, 36 00:02:08,400 --> 00:02:11,000 with the speaker, or just a string, it doesn't 37 00:02:11,039 --> 00:02:14,070 really matter here. Okay, so the robot can say hi, 38 00:02:14,100 --> 00:02:17,640 and say its name. Then the robot can also print 39 00:02:17,700 --> 00:02:21,510 all its internal information, including the name, 40 00:02:21,540 --> 00:02:25,140 version, number, temperature, etc. The robot can 41 00:02:25,140 --> 00:02:29,040 also initialize its hardware, and well, many more 42 00:02:29,040 --> 00:02:32,940 functionalities you can add when you need them. Here 43 00:02:32,940 --> 00:02:35,790 I keep it super basic and high level, we have a 44 00:02:35,790 --> 00:02:39,000 limited number of functionalities. But this is so 45 00:02:39,000 --> 00:02:43,710 we can focus 100% on understanding our topic. So 46 00:02:43,710 --> 00:02:46,980 we have defined attributes and functionalities for 47 00:02:46,980 --> 00:02:50,070 the robots. Now, if you want to implement that 48 00:02:50,100 --> 00:02:52,830 with Python code, you're going to create some 49 00:02:52,830 --> 00:02:56,040 variables for the first part, and some functions 50 00:02:56,130 --> 00:03:00,270 for the second part. So nothing new for now. Well, 51 00:03:00,330 --> 00:03:03,510 if you create a Robot class, you're simply going 52 00:03:03,510 --> 00:03:07,530 to group those variables and functions inside one 53 00:03:07,530 --> 00:03:11,760 structure that you're going to name Robot. And in 54 00:03:11,760 --> 00:03:15,030 a class, instead of using the word variable, 55 00:03:15,330 --> 00:03:18,720 we're going to use the word attribute and instead 56 00:03:18,720 --> 00:03:22,620 of function, we are going to use method. This is a 57 00:03:22,620 --> 00:03:26,700 quite useful convention to avoid confusions. Okay. 58 00:03:26,850 --> 00:03:29,550 So for example, here, the name of the Robot is a 59 00:03:29,550 --> 00:03:33,690 class attribute, and the init_hardware function is 60 00:03:33,690 --> 00:03:37,560 a class method. Now, as you can see, creating a 61 00:03:37,560 --> 00:03:40,590 class doesn't add any functionality or special 62 00:03:40,590 --> 00:03:43,830 behavior to the Robot. It's just a different way 63 00:03:43,830 --> 00:03:47,160 to organize and write the code. And speaking of 64 00:03:47,160 --> 00:03:50,100 writing, well, let's actually write that class 65 00:03:50,130 --> 00:03:51,338 with Python.