Now that we have the structure of the class with the constructor and the attributes,
let's implement the methods of the class or in
other words, the functionalities of the class.
And to create a method, well, it's almost the same
thing as to create a function like you did previously,
and we have already actually our first method, which is the constructor.
Now we can add any number of methods we want in the class,
so still with the indentation to stay inside of the class, and then def,
and then I want to implement the sayHi method.
And as you can see, so this is a functionality of PyCharm,
whenever I create a function or a method inside
a class, I automatically get the self parameter.
If you don't get it, you simply write it.
So self and we don't want any other parameter.
So as you can see, the first parameter of any method would be self.
Okay, so we have a reference to the objects we are currently using.
So the method is really linked to the object and to the class robot.
It's not just a function you can call from anywhere.
This is a specific function that is directly linked to robot
and you can only call it in relation to the robot class.
So sayHi, let's say we want to do so print.
Hello, my name is, and then let's do self.name.
So as you can see with the self keyword here, I can use self.name.
And because I have created self.name, this is going to work here,
okay, because I have initialized the variable or the
attributes, okay, and then I can use it in any other method.
Okay, and then plus, let's go back to a new line here.
Let's do ready to help.
Okay, so that's the sayHi method.
And then I'm going to come back.
So come back to the same indentation here and do def init hardware.
So again, we just need self.
I'm not going to add any other parameter.
Okay, colon.
And actually, it's better if I end the print with a parenthesis here.
And here, because this is just an example, I'm going to do print init hardware.
Okay, just going to use a print.
Okay, in real life, you would actually implement
this method to init the real hardware here.
We don't have any hardware, just an example.
So the point is to understand how OP, so let's use a print here.
So when we call that method, we can see that
we have actually called it and that it works.
And then I'm going to create another one, def, let's say print info.
Okay, again, with self, I don't need any other parameter.
And what I'm going to do here is I'm going to print all the info,
okay, which is the name, the version number, and internal temperature.
So I'm going first to do self.sayHi.
Okay, as you can see, I can directly call the method
of the class from another method of the class.
Okay, and to do that, I simply do self.sayHi.
Okay, if I just call sayHi, it's not going to work
because the function sayHi doesn't exist globally.
But the method sayHi exists inside the class robot.
So if I do self. I can get access to the different methods and attributes here.
Okay, so you can see how to call the method from another method.
And then let's say print.
So version number plus self version number, I'm going to cast this as a string,
because this is probably going to be an integer flow.
That can be a string, but we don't know.
Okay, the name here is probably going to be a string, so I don't need to cast it.
But here, let's take some precaution.
And then print temperature plus, and then the same self internal temperature.
Okay, so in this method, you can see we call
another method and we use the different attributes.
Okay, so self and the attributes.
If you want, you can also modify the attributes.
Okay, you just do self version number is equal to, and then you just change it.
Okay, that's not a problem.
So now we have a constructor, we have three attributes,
and we also have three methods inside the class.
All right, we have successfully written all the
functionalities of the class inside different methods.
And now let's go to the next step.