We now move to operator overload and.
But before starting with that, you'll have to note that all the python variables like strings, lists,
dictionaries
are all classes.
We could take a simple example on the strings.
Let's do a help train.
See, this is actually the string class which is used python.
Yeah.
We have some method defined so I could see.
So trains are actually classes, at least for you, not least.
See, you have something like that.
They.
There we go.
If we have two strings, this string one and we call it ABC.
No, we have an in the string string too.
We call it X, Y, Z.
Let's print out string one plus string.
So so we see how we combine this by simply doing what we just the year.
Now if we define some of the variables, the variable E, we'll call it three and then variable B we
call it for print is out.
We have a plus.
B, you see that in Python.
Although with the know with different kinds of variables, we see that for this same addition operator,
we are able to treat this two operations differently.
Now let's modify this slightly.
Suppose we have this call instead.
So we have string one
and string.
So let's run that.
You see that we have the same output we had when we just did the string, one plus string.
So let's come back to the string.
Help the search for ADD.
Okay, now that we go, we see that this string class actually has this ADD method and this method is
defined such that we have the current object so we see a self.
Plus the value we pass in.
And that's why.
Plus the object we pass in.
And that's why when we pass in the string object, we actually have the string, one plus string to
just like what we had done year.
Now this actually happens to be what we call operator overloading thanks to auto overloading.
We are able to, for example, put in this class here and then automatically heighten calls this method
for you and is able to join this too.
And then if we are working with a list, you see it's going to be similar is going to join the two lists.
If we're working with just this numbers, you see that as it up we can modify this say for example as
if the two are equal, see is false.
They are not the same.
Let's modify this.
We use that equal greater C.
It's not the same because social equal your.
So there we go.
So if those objects equals or object, we have that.
Now let's take this off.
We see how we could use simpler patterns like this.
And then this approach could be converted into your corresponding.
Methods in the Python classes now coming back to smiley class.
Let's define our equal method so we could define the equal method.
Yeah.
See, we have the object itself.
And then we have another object which will call it the as M Smiley.
That's the same object.
Accent, object.
There we go.
We can solve that is smile equals as some object that is smile.
So.
Right.
Yeah, we actually have two objects.
We have this current object that a self which is presented by the self we have this object which I give
is smile is the same as the other object is smile.
If they are the same, then we're supposed not to smile.
These are the same.
So for now, let's run this.
It's an area of no doubt when defining this operators.
We need to have the double on this cause before and also after.
And this method names aren't just some names we just guessing the actually in the python documentation
for equals for equals is this for addition as we've seen is this.
For subtraction is SOP.
Anyway, let's do this.
Yeah.
So let's copy that.
And then for multiplication.
Small for division.
We have to leave that to these and many artists so you could check on the documentation to see the exact
method names we're going to use.
So coming back to this, we have this equal does echo.
Then we've decided to say that two smileys are the same.
If the is smile attributes at the same one, this is fine.
We'll define happy.
I would define that.
So here again, let's now call in the equal method.
So here we have side the equal which takes in happy run.
That is false.
They are not the same.
Let's modify this.
We see they are actually the same.
Not equal is actually not equal.
So let's not do that.
Let's have that same.
It's okay.
And then it's not equal.
Take this off on that.
And now that's modified this.
Yeah, we have not equal.
Okay, but not equal is supposed to be different.
So let's put that wrong again.
And there we go.
We have not equal which is true states of not equal is true.
So it means that sad and happy and not equal.
Now what's interesting about overloading is that instead of doing this, we could simply see sad.
I'll do that.
I would say have the same response.
So let's say instead of having this.
Instead of having this.
Sprint is out.
So we say that instead of having instead of having to put it all like this, all we need to do is just
now do this.
So let's run that.
Now let's come back to this year.
And then commanders can see what we're getting now.
So we have the same answer.
Let's modify this and say equal.
You see now is false.
So this means we have the power to modify what our smiley thinks is o different smiley from itself.
So the fact that we could modify this means if we want to say, for example, that for is for the equality
of one, say for example, that for the two smiles to be equal or for the to smile is not be equal.
We could specify that this is equal.
So this could be equal.
And and.
We have.
So that's at this.
So to say that they are not equal, this could be equal and the the face colors could be different.
So let's just copy this.
Copy that.
Now we just have this color face color.
Face colour.
So the face colour is different.
It's going to be different from this now.
You see that in this case is false and that is because the face color is different.
It's common.
This we still have the false.
Now let's take this.
Dear friend, you have to take this.
We have truth to the modified is we have.
Or then we suppose that if they have this as if the face colors are the same said that's true.
See, this is not true.
So the point we're trying to make here is we could simply use this kind of operators and then based
on the class definitions, Python can automatically come up with some results.
Let's consider again the object happy of the cross smiley to call on the set or out of the hat area
method.
Yeah we could have happy that hat area and then it gives us a hat area for that.
Smiley Obviously we're getting the default values.
We could say radius radius equals C two.
There we go.
We have a different value now.
We could actually call this class as if it were a function.
And to do that, we make use of the call operator overload.
So we have the call.
You have that now?
Yeah.
We shall return simply the head area.
So we call in the head area method.
That's fine.
Let's run this.
We'll see how this works now.
So yeah, we print printers out, printers out, print this, print this.
Now we have happy now this actually is our object which I just simply call that out goes on here is
want to call this once we call this object here as a function it's going to use or be as if we're making
a call on this method right here.
So let's run.
And there we go.
We have the same answer.
If we take this off this, we tend to that.
I'll see.
That's it.
So that's the call operator of a loader.