Hello, in this Python video, we are going to look at overloading operators. So an operator is something like equals is something like, you know, plus, these are operators. And if we were to try and add two classes together, that's not really going to work. But what we can do is overload an operator. So we can provide specific functionality. So you could, you know, add two classes together, you could take away two classes, you could change the way they know, compare, we're just going to use the example of ad, but we'll provide a link so you can see all the other sort of methods that you can change as well.
So for this vehicle, right here, we've got a speed value. We have a speed value, and we're going to overload a method. So we're gonna do we're just going to school indentation. All right. So that's the method for adding a plus. And first of all, just itself, then come on and say, the vehicle.
So this will be the other vehicle, all of the other instance objects that we're not gonna specifically pass in. And we will just do with time, because we're going to return to the point where we, you know, do the addition. And what we are going to return is essentially, just the, you can do a bunch of things. So you could create a whole nother vehicle object or you could do something like vehicle and, you know, return this object with the new value of speed and, you know, pass it in to here. Yeah, you know, let's have a go doing that. I was gonna return a simple value, but let's make it a bit more complex.
Self dot speed, other vehicle speed. And that's it. So we've overloaded it, and all arrows have disappeared. Let's go down so we got it. So from the previous printout speed for call one and two is five and 89. at this particular point, if I were to do if I were to do if I created a number cause I call this call three, I could say call one call to no error of the print call free dot speed. So let's see what we get.
Run it and we get 94 is because when we added call one call to the this overloaded operator was invoked and as a result We created a new vehicle class or object that got returned, which got assigned to this Laporta that we pass in the speed from the first object speed from the second object added them together. And because our init method had this part of the init method as a parameter, we have to set a new value for speed. That's it for overloading operators. Honestly, there's not much more to it than that. Obviously, you can find more functionality, maybe the adding adds a lot more. No, keeps track of a few things, maybe add stuff to dictionary, you know, that's all fine.
You can do whatever you want. But the core essence, we've covered that Luxor, there'll be a link with the video that will help you with all the other operators that you can overload as well. That's it. Thank you for watching. I look forward to seeing you in the next video.