1
00:00:00,910 --> 00:00:05,630
Everything in the Python program is an interaction between different entities.

2
00:00:05,650 --> 00:00:09,490
For example, we have libraries such as pandas.

3
00:00:09,490 --> 00:00:12,940
We have statements such as import.

4
00:00:13,910 --> 00:00:20,240
The return statement that if statement, the statement we have keywords such as the class keywords,

5
00:00:20,240 --> 00:00:21,590
def keywords.

6
00:00:22,650 --> 00:00:27,690
Then we have classes such as this block of code here.

7
00:00:27,690 --> 00:00:29,640
That's an entire class.

8
00:00:32,390 --> 00:00:34,850
Then we had instances.

9
00:00:34,850 --> 00:00:38,180
This year is an instance of a hotel class.

10
00:00:38,180 --> 00:00:40,490
That's another instance of.

11
00:00:41,160 --> 00:00:43,000
The hotel class as well.

12
00:00:43,020 --> 00:00:46,980
This string here is an instance of a string class.

13
00:00:47,550 --> 00:00:50,100
This other string is also an instance.

14
00:00:50,900 --> 00:00:52,130
Or for string class.

15
00:00:52,130 --> 00:00:53,390
Then we had.

16
00:00:54,170 --> 00:00:54,980
Functions.

17
00:00:54,980 --> 00:00:59,180
Which are these outside of classes?

18
00:01:00,910 --> 00:01:05,470
And then we have methods which are like functions, but they are inside classes.

19
00:01:06,320 --> 00:01:09,410
Such as this method here and that method there.

20
00:01:10,440 --> 00:01:18,030
So a Python program consists of interaction between things like functions and instances and methods.

21
00:01:18,090 --> 00:01:29,010
Even when you do things like ease the hello instance, the hello string instance equal to the high string

22
00:01:29,010 --> 00:01:29,820
instance.

23
00:01:30,540 --> 00:01:36,680
Even when you do that, what you're actually doing is you're calling a method.

24
00:01:36,690 --> 00:01:44,550
In this case it would be this method underscore, underscore, e, q, underscore, underscore.

25
00:01:46,000 --> 00:01:46,710
Hi.

26
00:01:49,310 --> 00:01:51,040
And you get the same output.

27
00:01:51,050 --> 00:01:54,290
Actually, you are not the one who are calling this method.

28
00:01:54,290 --> 00:01:58,870
The interpreter is calling this method on the background.

29
00:01:58,880 --> 00:02:05,690
So this is implicitly called and this here is known as syntactic sugar.

30
00:02:06,410 --> 00:02:14,000
You can think of syntactic sugar as simplified syntax so that you don't have to write that methods you

31
00:02:14,000 --> 00:02:14,770
can just do.

32
00:02:14,780 --> 00:02:15,590
Hello.

33
00:02:15,980 --> 00:02:17,550
Is equal to high.

34
00:02:17,570 --> 00:02:19,800
So that's more readable basically.

35
00:02:19,820 --> 00:02:23,420
Other examples would be one plus two.

36
00:02:23,900 --> 00:02:27,100
That would be the equivalent of one space dot.

37
00:02:27,200 --> 00:02:33,380
You have to use a space with numbers because it can be confused.

38
00:02:33,530 --> 00:02:39,590
Python doesn't doesn't know if it's a float or an integer if you don't provide space.

39
00:02:39,590 --> 00:02:44,090
So that would be add to and you get three.

40
00:02:44,690 --> 00:02:48,680
So when you do that, you're calling the ADD method.

41
00:02:48,680 --> 00:02:54,560
Actually now you can see a list of magic methods when you use there.

42
00:02:54,560 --> 00:02:59,780
For example, dear hello or just dear store.

43
00:03:00,820 --> 00:03:04,750
And you'll see the methods available for STR.

44
00:03:08,800 --> 00:03:17,920
Similarly, we can check for magic methods that our classes possess because STR is a class, right?

45
00:03:17,950 --> 00:03:19,500
Hotel is also a class.

46
00:03:19,510 --> 00:03:23,570
So let's copy this class in the python castle.

47
00:03:23,590 --> 00:03:26,140
You can either copy the entire class or.

48
00:03:28,380 --> 00:03:29,880
You can improve that class.

49
00:03:29,880 --> 00:03:33,330
But first, I'd like to remove all these.

50
00:03:37,680 --> 00:03:45,270
Let's just keep the definition of the classes here, save the script, and then from main, that's main

51
00:03:45,270 --> 00:03:49,320
to main to import the hotel class.

52
00:03:50,890 --> 00:03:56,170
Now hotel is available as a name in this Python session.

53
00:03:56,170 --> 00:04:03,790
And I can do Dear Hotel and you'll see that the hotel class has all these magic methods.

54
00:04:06,200 --> 00:04:08,270
Among the methods we will see.

55
00:04:08,660 --> 00:04:10,510
Underscore underscore e.

56
00:04:10,520 --> 00:04:16,100
Q So as you saw, that was the equivalent of this operator.

57
00:04:16,100 --> 00:04:23,390
So let's try to use this operator with two instances of the hotel class, right?

58
00:04:23,390 --> 00:04:28,610
Just like we used here, that operator with two instances of the string class.

59
00:04:28,610 --> 00:04:30,950
So hello is an instance of a string class.

60
00:04:31,220 --> 00:04:33,580
How is also an instance of string class?

61
00:04:33,590 --> 00:04:35,480
So let's do the same here.

62
00:04:35,930 --> 00:04:37,250
Let's create two instances.

63
00:04:37,250 --> 00:04:39,800
First, that would be hotel.

64
00:04:39,800 --> 00:04:44,810
You can either store them in variables or you can compare them directly.

65
00:04:44,810 --> 00:04:46,340
I'll store them in variables.

66
00:04:46,550 --> 00:04:47,930
So hotel.

67
00:04:49,080 --> 00:04:51,090
What do we need to provide?

68
00:04:51,270 --> 00:04:53,250
We need to provide the hotel ID.

69
00:04:53,280 --> 00:04:58,830
I'll just pass directly the value without mentioning the arguments you can do either way.

70
00:04:58,950 --> 00:05:00,270
So that would be.

71
00:05:01,600 --> 00:05:04,510
188 rate 188.

72
00:05:07,920 --> 00:05:12,990
I'll do another hotel instance and I'll provide the same.

73
00:05:14,040 --> 00:05:15,630
I'd actually.

74
00:05:17,130 --> 00:05:24,120
Still, these are treated as two different instances by Python.

75
00:05:24,120 --> 00:05:31,020
So if you do hotel, one is equal to hotel two, you get false.

76
00:05:32,360 --> 00:05:33,140
Why?

77
00:05:33,620 --> 00:05:40,310
Well, because these are basically treated as two different objects.

78
00:05:40,460 --> 00:05:47,570
And you can keep creating more hotel instances using the same ID, you can create ten of them and you

79
00:05:47,570 --> 00:05:51,830
can compare any of them, and all of them will be different from each other.

80
00:05:52,160 --> 00:05:55,160
That is not the case with things like strings, right?

81
00:05:55,190 --> 00:05:58,820
Hello is equal to hello and we get true.

82
00:05:59,630 --> 00:06:08,720
That is because the class string, when it was defined by some developers in the code developer team

83
00:06:08,960 --> 00:06:17,180
or the Python organization, they have overwritten the ECC methods.

84
00:06:17,180 --> 00:06:26,870
So this method and we can do the same so that when we compare hotel one and hotel two, if they have

85
00:06:26,870 --> 00:06:30,410
the same ID, we will return false.

86
00:06:30,410 --> 00:06:32,060
That should return false.

87
00:06:32,120 --> 00:06:34,490
So let's do that in our code.

88
00:06:34,820 --> 00:06:36,890
Let's overwrite that.

89
00:06:37,620 --> 00:06:39,120
E q methods.

90
00:06:39,120 --> 00:06:42,560
So we will change the behavior of that method.

91
00:06:42,570 --> 00:06:44,820
So let's go to the hotel class.

92
00:06:45,870 --> 00:06:52,050
Normally you add magic methods at the end, so after the last method, but make sure to be inside the

93
00:06:52,050 --> 00:06:57,900
class and write, define, underscore, underscore e Q The name has to be the same.

94
00:06:58,140 --> 00:06:59,490
Exactly the same.

95
00:07:00,060 --> 00:07:03,870
You'll see this gets this special color in Python.

96
00:07:03,990 --> 00:07:10,380
And now you want to specify how do you want this method to behave?

97
00:07:10,620 --> 00:07:16,260
So when do you want to treat two instances as being the same as being equal?

98
00:07:16,260 --> 00:07:20,280
Well, I think if self taught.

99
00:07:21,690 --> 00:07:22,650
Hotel.

100
00:07:25,020 --> 00:07:28,800
So this idea is.

101
00:07:30,910 --> 00:07:34,750
Equal to self dot hotel ID.

102
00:07:35,200 --> 00:07:37,000
Then we return true.

103
00:07:37,720 --> 00:07:41,230
Else we return false.

104
00:07:41,230 --> 00:07:42,550
Save the script.

105
00:07:42,570 --> 00:07:45,430
Then make sure to close this python session.

106
00:07:45,430 --> 00:07:48,160
You need to reopen a python session again.

107
00:07:48,160 --> 00:07:53,020
Otherwise you will be working on the old class which doesn't have the queue.

108
00:07:53,170 --> 00:07:56,290
Sorry, the queue method.

109
00:07:56,290 --> 00:07:58,990
So import in a new python session.

110
00:07:58,990 --> 00:08:04,270
Import from main to import hotel again.

111
00:08:07,910 --> 00:08:11,060
Create two instances hotel one with hotel.

112
00:08:12,170 --> 00:08:13,400
188.

113
00:08:15,530 --> 00:08:19,960
A hotel to Ace Hotel 188.

114
00:08:20,950 --> 00:08:24,280
Now, Hotel one is equal to Hotel two.

115
00:08:26,030 --> 00:08:26,570
Initially.

116
00:08:26,570 --> 00:08:27,590
We're going to get an error.

117
00:08:27,590 --> 00:08:32,929
And I'm glad this error happened because now you can understand a key concept here.

118
00:08:33,230 --> 00:08:34,350
So let's read the error.

119
00:08:34,370 --> 00:08:40,570
It says hotel IQ takes one positional argument, but two were given.

120
00:08:40,580 --> 00:08:47,000
So hotel IQ takes one positional arguments, which is true, right?

121
00:08:47,480 --> 00:08:50,960
It's only takes self a port.

122
00:08:50,960 --> 00:08:53,600
Two arguments were given here.

123
00:08:54,080 --> 00:08:59,840
What is the second argument that we've given to this IQ methods?

124
00:08:59,840 --> 00:09:04,040
Well, the second argument is the second instance, right.

125
00:09:04,040 --> 00:09:07,100
Because this here is equivalent of.

126
00:09:08,410 --> 00:09:10,030
Doing hotel.

127
00:09:10,330 --> 00:09:12,700
Actually, it's the equivalent of doing hotel.

128
00:09:12,700 --> 00:09:22,420
The class dot e, Q underscore underscore Hotel one, Hotel two.

129
00:09:24,260 --> 00:09:25,820
That's what we're doing.

130
00:09:25,820 --> 00:09:30,080
So we should reflect that syntax in here.

131
00:09:30,710 --> 00:09:33,530
So we should go there and add something like other.

132
00:09:35,980 --> 00:09:41,110
And then self should be updated to other here.

133
00:09:42,480 --> 00:09:45,630
So basically we are comparing.

134
00:09:47,450 --> 00:09:55,820
This current instance hotel one with this other instance which is passed as the second argument hotel

135
00:09:55,820 --> 00:09:56,690
to in this case.

136
00:09:56,690 --> 00:10:00,290
So hotel to that ID and so on.

137
00:10:01,380 --> 00:10:01,580
Right.

138
00:10:01,580 --> 00:10:03,020
So save that script.

139
00:10:04,190 --> 00:10:09,920
Close that Python console imports Again, you can use the upper arrow key to call previously executed

140
00:10:09,920 --> 00:10:10,630
statements.

141
00:10:10,640 --> 00:10:13,280
Import hotel creates a hotel.

142
00:10:13,280 --> 00:10:17,540
One instance creates a hotel, two instance with the upper arrow key.

143
00:10:17,780 --> 00:10:19,820
Compare the two.

144
00:10:20,480 --> 00:10:23,050
It should be this one and we get true.

145
00:10:23,060 --> 00:10:31,950
So now we can successfully compare two instances and evaluate them as true if they have the same idea.

146
00:10:31,970 --> 00:10:34,580
So this could be useful in your program.

147
00:10:36,310 --> 00:10:43,000
If you want to expand your program, for example, and you want to see if two hotel instances are the

148
00:10:43,000 --> 00:10:43,720
same.

149
00:10:44,290 --> 00:10:50,320
So to do that, you can just compare them like that, like you do with other.

150
00:10:51,580 --> 00:10:52,960
Instances.

151
00:10:53,350 --> 00:10:56,860
Types such as strings or numbers.

152
00:10:57,400 --> 00:11:00,550
So similarly, you can add more magic methods.

153
00:11:00,550 --> 00:11:03,490
You can override more magic methods here.

154
00:11:03,940 --> 00:11:09,190
Perhaps it makes sense to add to one hotel to another.

155
00:11:09,190 --> 00:11:17,620
So if that makes sense for your program, then you want to write exactly the behavior of what should

156
00:11:17,620 --> 00:11:21,280
happen when you add those two hotels together.

157
00:11:21,460 --> 00:11:25,900
So perhaps you want to access self that price.

158
00:11:25,930 --> 00:11:31,270
If you had a price instance variable, which we don't have in this case, but if you had one, you would

159
00:11:31,270 --> 00:11:37,660
do something like sell that price plus other that price.

160
00:11:37,660 --> 00:11:38,860
So you could.

161
00:11:40,750 --> 00:11:49,240
Add them at a total in a total variable, you could store them at other here and then return total.

162
00:11:49,240 --> 00:11:58,030
And then when you do hotel one plus hotel two, you would get the total price as.

163
00:11:59,280 --> 00:12:00,000
Output.

164
00:12:00,000 --> 00:12:01,800
So that would be a number.

165
00:12:03,460 --> 00:12:12,370
So I'm deleting that and that just to show you how it would be if you use the add magic method.

166
00:12:12,520 --> 00:12:19,480
So that was some magic about Python and you can try to experiment with more methods if you want to have

167
00:12:19,480 --> 00:12:20,980
some python fun.

168
00:12:21,400 --> 00:12:24,970
And I'll leave this lecture at this point.

169
00:12:24,970 --> 00:12:31,690
I hope this makes sense and it gives you some more advanced knowledge about how Python works, the inner

170
00:12:31,690 --> 00:12:33,160
works of Python.

171
00:12:33,520 --> 00:12:36,660
And yeah, I'll talk to you in the next videos.

172
00:12:36,670 --> 00:12:37,750
Thanks a lot for following.

173
00:12:37,750 --> 00:12:39,200
I'm very happy to have you here.

174
00:12:39,220 --> 00:12:39,640
See you.

