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, you can do type with 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 am 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 the 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're probably never going to use in real
life. So let's say you want to code the behavior
for a robot. And we're going to stay at very high
level here for the example. So we do think about
what kind of attributes a robot can have. For
example, the name, the 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 the 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, we have a
limited number of functionalities. But this is so
we can focus 100% on understanding our topic. So
we have defined attributes and functionalities for
the robots. Now, if you want to implement that
with Python code, you're 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're simply going
to group those variables and functions inside one
structure that you're going to name Robot. And in
a class, instead of using the word variable,
we're 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.