1
00:00:00,790 --> 00:00:03,670
We now move to operator overload and.

2
00:00:07,080 --> 00:00:15,570
But before starting with that, you'll have to note that all the python variables like strings, lists,

3
00:00:17,760 --> 00:00:18,810
dictionaries

4
00:00:21,240 --> 00:00:22,950
are all classes.

5
00:00:23,850 --> 00:00:26,670
We could take a simple example on the strings.

6
00:00:27,390 --> 00:00:29,280
Let's do a help train.

7
00:00:29,760 --> 00:00:34,110
See, this is actually the string class which is used python.

8
00:00:34,590 --> 00:00:34,890
Yeah.

9
00:00:34,890 --> 00:00:39,420
We have some method defined so I could see.

10
00:00:44,180 --> 00:00:50,990
So trains are actually classes, at least for you, not least.

11
00:00:51,020 --> 00:00:52,280
See, you have something like that.

12
00:00:52,580 --> 00:00:52,910
They.

13
00:00:54,230 --> 00:00:55,010
There we go.

14
00:00:55,820 --> 00:01:02,400
If we have two strings, this string one and we call it ABC.

15
00:01:02,900 --> 00:01:04,820
No, we have an in the string string too.

16
00:01:04,820 --> 00:01:08,600
We call it X, Y, Z.

17
00:01:09,980 --> 00:01:15,020
Let's print out string one plus string.

18
00:01:15,500 --> 00:01:20,810
So so we see how we combine this by simply doing what we just the year.

19
00:01:21,410 --> 00:01:29,980
Now if we define some of the variables, the variable E, we'll call it three and then variable B we

20
00:01:29,990 --> 00:01:32,360
call it for print is out.

21
00:01:32,360 --> 00:01:34,100
We have a plus.

22
00:01:34,100 --> 00:01:36,800
B, you see that in Python.

23
00:01:38,030 --> 00:01:44,330
Although with the know with different kinds of variables, we see that for this same addition operator,

24
00:01:44,840 --> 00:01:48,350
we are able to treat this two operations differently.

25
00:01:49,250 --> 00:01:51,710
Now let's modify this slightly.

26
00:01:51,890 --> 00:01:55,190
Suppose we have this call instead.

27
00:01:55,220 --> 00:01:56,720
So we have string one

28
00:01:59,210 --> 00:02:01,790
and string.

29
00:02:01,880 --> 00:02:03,320
So let's run that.

30
00:02:03,470 --> 00:02:08,900
You see that we have the same output we had when we just did the string, one plus string.

31
00:02:08,900 --> 00:02:12,500
So let's come back to the string.

32
00:02:13,160 --> 00:02:16,370
Help the search for ADD.

33
00:02:18,140 --> 00:02:26,630
Okay, now that we go, we see that this string class actually has this ADD method and this method is

34
00:02:26,630 --> 00:02:33,980
defined such that we have the current object so we see a self.

35
00:02:35,740 --> 00:02:38,350
Plus the value we pass in.

36
00:02:38,590 --> 00:02:39,310
And that's why.

37
00:02:39,580 --> 00:02:41,080
Plus the object we pass in.

38
00:02:41,260 --> 00:02:46,960
And that's why when we pass in the string object, we actually have the string, one plus string to

39
00:02:47,200 --> 00:02:49,480
just like what we had done year.

40
00:02:51,400 --> 00:02:57,460
Now this actually happens to be what we call operator overloading thanks to auto overloading.

41
00:02:57,730 --> 00:03:07,240
We are able to, for example, put in this class here and then automatically heighten calls this method

42
00:03:07,330 --> 00:03:10,690
for you and is able to join this too.

43
00:03:11,110 --> 00:03:16,360
And then if we are working with a list, you see it's going to be similar is going to join the two lists.

44
00:03:16,360 --> 00:03:24,040
If we're working with just this numbers, you see that as it up we can modify this say for example as

45
00:03:24,300 --> 00:03:26,230
if the two are equal, see is false.

46
00:03:26,230 --> 00:03:27,040
They are not the same.

47
00:03:27,820 --> 00:03:29,080
Let's modify this.

48
00:03:29,080 --> 00:03:31,300
We use that equal greater C.

49
00:03:31,600 --> 00:03:33,850
It's not the same because social equal your.

50
00:03:34,930 --> 00:03:36,030
So there we go.

51
00:03:36,040 --> 00:03:39,220
So if those objects equals or object, we have that.

52
00:03:39,760 --> 00:03:40,960
Now let's take this off.

53
00:03:42,640 --> 00:03:45,850
We see how we could use simpler patterns like this.

54
00:03:46,120 --> 00:03:50,050
And then this approach could be converted into your corresponding.

55
00:03:53,770 --> 00:03:59,230
Methods in the Python classes now coming back to smiley class.

56
00:03:59,650 --> 00:04:05,140
Let's define our equal method so we could define the equal method.

57
00:04:06,160 --> 00:04:06,660
Yeah.

58
00:04:07,810 --> 00:04:09,370
See, we have the object itself.

59
00:04:09,370 --> 00:04:15,200
And then we have another object which will call it the as M Smiley.

60
00:04:15,220 --> 00:04:16,270
That's the same object.

61
00:04:16,540 --> 00:04:17,470
Accent, object.

62
00:04:18,490 --> 00:04:19,300
There we go.

63
00:04:19,720 --> 00:04:30,430
We can solve that is smile equals as some object that is smile.

64
00:04:30,850 --> 00:04:31,210
So.

65
00:04:31,210 --> 00:04:31,490
Right.

66
00:04:31,510 --> 00:04:33,400
Yeah, we actually have two objects.

67
00:04:33,490 --> 00:04:40,330
We have this current object that a self which is presented by the self we have this object which I give

68
00:04:40,840 --> 00:04:45,310
is smile is the same as the other object is smile.

69
00:04:45,370 --> 00:04:48,340
If they are the same, then we're supposed not to smile.

70
00:04:48,340 --> 00:04:49,060
These are the same.

71
00:04:49,420 --> 00:04:51,580
So for now, let's run this.

72
00:04:53,110 --> 00:04:57,580
It's an area of no doubt when defining this operators.

73
00:04:57,580 --> 00:05:02,050
We need to have the double on this cause before and also after.

74
00:05:02,860 --> 00:05:11,470
And this method names aren't just some names we just guessing the actually in the python documentation

75
00:05:11,740 --> 00:05:16,720
for equals for equals is this for addition as we've seen is this.

76
00:05:19,540 --> 00:05:21,790
For subtraction is SOP.

77
00:05:22,450 --> 00:05:23,440
Anyway, let's do this.

78
00:05:23,470 --> 00:05:23,860
Yeah.

79
00:05:24,400 --> 00:05:26,920
So let's copy that.

80
00:05:27,730 --> 00:05:31,090
And then for multiplication.

81
00:05:31,270 --> 00:05:34,510
Small for division.

82
00:05:35,350 --> 00:05:47,260
We have to leave that to these and many artists so you could check on the documentation to see the exact

83
00:05:47,620 --> 00:05:49,090
method names we're going to use.

84
00:05:49,870 --> 00:05:53,290
So coming back to this, we have this equal does echo.

85
00:05:53,890 --> 00:05:57,460
Then we've decided to say that two smileys are the same.

86
00:05:57,460 --> 00:06:02,260
If the is smile attributes at the same one, this is fine.

87
00:06:02,260 --> 00:06:03,190
We'll define happy.

88
00:06:03,190 --> 00:06:04,090
I would define that.

89
00:06:04,630 --> 00:06:10,240
So here again, let's now call in the equal method.

90
00:06:10,270 --> 00:06:17,920
So here we have side the equal which takes in happy run.

91
00:06:17,920 --> 00:06:19,080
That is false.

92
00:06:19,090 --> 00:06:19,870
They are not the same.

93
00:06:21,550 --> 00:06:22,660
Let's modify this.

94
00:06:23,050 --> 00:06:25,030
We see they are actually the same.

95
00:06:25,480 --> 00:06:27,010
Not equal is actually not equal.

96
00:06:27,010 --> 00:06:27,970
So let's not do that.

97
00:06:27,970 --> 00:06:29,200
Let's have that same.

98
00:06:29,870 --> 00:06:30,700
It's okay.

99
00:06:32,170 --> 00:06:34,300
And then it's not equal.

100
00:06:34,570 --> 00:06:35,950
Take this off on that.

101
00:06:37,420 --> 00:06:39,070
And now that's modified this.

102
00:06:39,070 --> 00:06:41,260
Yeah, we have not equal.

103
00:06:43,240 --> 00:06:44,920
Okay, but not equal is supposed to be different.

104
00:06:44,920 --> 00:06:47,110
So let's put that wrong again.

105
00:06:48,430 --> 00:06:49,090
And there we go.

106
00:06:49,090 --> 00:06:54,580
We have not equal which is true states of not equal is true.

107
00:06:54,730 --> 00:06:58,450
So it means that sad and happy and not equal.

108
00:06:59,440 --> 00:07:07,540
Now what's interesting about overloading is that instead of doing this, we could simply see sad.

109
00:07:09,340 --> 00:07:10,060
I'll do that.

110
00:07:11,880 --> 00:07:13,680
I would say have the same response.

111
00:07:13,680 --> 00:07:17,190
So let's say instead of having this.

112
00:07:19,630 --> 00:07:20,770
Instead of having this.

113
00:07:24,980 --> 00:07:25,790
Sprint is out.

114
00:07:30,180 --> 00:07:35,460
So we say that instead of having instead of having to put it all like this, all we need to do is just

115
00:07:35,700 --> 00:07:36,570
now do this.

116
00:07:37,200 --> 00:07:38,040
So let's run that.

117
00:07:38,070 --> 00:07:39,720
Now let's come back to this year.

118
00:07:39,720 --> 00:07:42,330
And then commanders can see what we're getting now.

119
00:07:43,650 --> 00:07:44,910
So we have the same answer.

120
00:07:45,540 --> 00:07:49,500
Let's modify this and say equal.

121
00:07:52,740 --> 00:07:54,050
You see now is false.

122
00:07:54,300 --> 00:08:05,190
So this means we have the power to modify what our smiley thinks is o different smiley from itself.

123
00:08:05,880 --> 00:08:12,930
So the fact that we could modify this means if we want to say, for example, that for is for the equality

124
00:08:12,930 --> 00:08:17,940
of one, say for example, that for the two smiles to be equal or for the to smile is not be equal.

125
00:08:18,450 --> 00:08:21,150
We could specify that this is equal.

126
00:08:21,360 --> 00:08:22,560
So this could be equal.

127
00:08:22,980 --> 00:08:25,650
And and.

128
00:08:28,810 --> 00:08:29,500
We have.

129
00:08:29,950 --> 00:08:31,000
So that's at this.

130
00:08:32,780 --> 00:08:39,170
So to say that they are not equal, this could be equal and the the face colors could be different.

131
00:08:39,170 --> 00:08:40,820
So let's just copy this.

132
00:08:43,510 --> 00:08:44,440
Copy that.

133
00:08:47,150 --> 00:08:51,050
Now we just have this color face color.

134
00:08:54,660 --> 00:08:55,530
Face colour.

135
00:08:56,820 --> 00:08:58,440
So the face colour is different.

136
00:09:01,620 --> 00:09:04,050
It's going to be different from this now.

137
00:09:06,080 --> 00:09:09,500
You see that in this case is false and that is because the face color is different.

138
00:09:09,990 --> 00:09:10,460
It's common.

139
00:09:10,460 --> 00:09:12,410
This we still have the false.

140
00:09:13,490 --> 00:09:14,450
Now let's take this.

141
00:09:14,630 --> 00:09:19,010
Dear friend, you have to take this.

142
00:09:20,060 --> 00:09:23,150
We have truth to the modified is we have.

143
00:09:23,150 --> 00:09:30,490
Or then we suppose that if they have this as if the face colors are the same said that's true.

144
00:09:30,520 --> 00:09:31,950
See, this is not true.

145
00:09:33,230 --> 00:09:40,310
So the point we're trying to make here is we could simply use this kind of operators and then based

146
00:09:40,310 --> 00:09:45,440
on the class definitions, Python can automatically come up with some results.

147
00:09:46,190 --> 00:09:57,140
Let's consider again the object happy of the cross smiley to call on the set or out of the hat area

148
00:09:57,680 --> 00:09:58,160
method.

149
00:09:58,160 --> 00:10:04,010
Yeah we could have happy that hat area and then it gives us a hat area for that.

150
00:10:04,010 --> 00:10:06,350
Smiley Obviously we're getting the default values.

151
00:10:06,620 --> 00:10:12,350
We could say radius radius equals C two.

152
00:10:12,710 --> 00:10:13,190
There we go.

153
00:10:13,190 --> 00:10:15,650
We have a different value now.

154
00:10:15,950 --> 00:10:19,940
We could actually call this class as if it were a function.

155
00:10:21,740 --> 00:10:24,780
And to do that, we make use of the call operator overload.

156
00:10:25,040 --> 00:10:27,530
So we have the call.

157
00:10:28,530 --> 00:10:31,100
You have that now?

158
00:10:31,100 --> 00:10:31,300
Yeah.

159
00:10:31,310 --> 00:10:34,970
We shall return simply the head area.

160
00:10:37,190 --> 00:10:38,810
So we call in the head area method.

161
00:10:39,080 --> 00:10:39,740
That's fine.

162
00:10:40,730 --> 00:10:41,690
Let's run this.

163
00:10:42,110 --> 00:10:44,000
We'll see how this works now.

164
00:10:44,390 --> 00:10:51,710
So yeah, we print printers out, printers out, print this, print this.

165
00:10:53,420 --> 00:11:00,830
Now we have happy now this actually is our object which I just simply call that out goes on here is

166
00:11:00,830 --> 00:11:11,300
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

167
00:11:11,300 --> 00:11:13,280
a call on this method right here.

168
00:11:13,730 --> 00:11:14,570
So let's run.

169
00:11:15,230 --> 00:11:15,800
And there we go.

170
00:11:15,800 --> 00:11:17,090
We have the same answer.

171
00:11:17,600 --> 00:11:20,000
If we take this off this, we tend to that.

172
00:11:20,000 --> 00:11:20,720
I'll see.

173
00:11:20,720 --> 00:11:21,110
That's it.

174
00:11:21,650 --> 00:11:24,980
So that's the call operator of a loader.
