First of all, OOP is everywhere in Python.
And to get the proof of that, let's just come back to what we have used before.
If you remember, when we use type, for example,
with an integer value, we get class int.
If you do type with a string value, for example, test here, you get class str.
You can see here the keyword class, which is
directly related to object-oriented programming.
I'm going to explain what a class is in just a
moment, but for now you can see that even the
most basic Python data types are actually using OOP.
And this is going to be the same for most of the Python modules you are going to use.
Now let's understand what is OOP.
So object-oriented programming is a way of
organizing your code into what we call classes.
A class is basically a structure you can use to then create an object in your code.
And what do you put inside a class?
Well, two kinds of things.
Variables and functions, which are of course related to the class.
And let's see with an example actually, because
I don't want to lose you with too much theory.
Because I like robots and I mainly work with robotics
programming, let's use a robot as an example.
This will change from the classic animal or vehicle class example,
which is always the same in every tutorial and which
you are probably never going to use in real life.
So let's say you want to code the behavior for a robot.
And we are going to stay at a very high level here for the example.
So we need to think about what kind of attributes a robot can have.
For example, a name, a version number, the
internal temperature of the robot, etc. etc.
Let's keep it short.
And then what functionalities the robot has.
So for example, the robot can say hi with a speaker or just a string.
It doesn't really matter here.
Okay, so the robot can say hi and say its name.
Then the robot can also print all its internal information,
including the name, version number, temperature, etc.
The robot can also initialize its hardware.
And well, many more functionalities you can add when you need them.
Here I keep it super basic and high level with a limited number of functionalities.
But this is so we can focus 100% on understanding OOP.
So we have defined attributes and functionalities for the robot.
Now, if you want to implement that with Python code,
you are going to create some variables for the
first part and some functions for the second part.
So nothing new for now.
Well, if you create a robot class, you are simply going to group
those variables and functions inside one
structure that you are going to name "robot".
And in a class, instead of using the word
"variable", we are going to use the word "attribute".
And instead of "function", we are going to use "method".
This is a quite useful convention to avoid confusions.
Okay, so for example here, the name of the robot is a class attribute
and the init hardware function is a class method.
Now, as you can see, creating a class doesn't add
any functionality or special behavior to the robot.
It's just a different way to organize and write the code.
And speaking of writing, well, let's actually write that class with Python.