Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,380 --> 00:00:01,910
All right.
2
00:00:01,940 --> 00:00:04,970
In this video I'm going to try and tricky.
3
00:00:05,190 --> 00:00:11,020
I want you to look at these expressions where I'm checking for equality right.
4
00:00:11,040 --> 00:00:18,720
I'm saying hey does true equal four one does empty string equal one due to race equal that are empty
5
00:00:18,750 --> 00:00:26,540
equal while each other now pause a video here and try to guess what the outcomes of this are going to
6
00:00:26,540 --> 00:00:27,950
be.
7
00:00:28,200 --> 00:00:28,940
Ready.
8
00:00:29,130 --> 00:00:31,410
By the way if you get one hundred percent on this wall.
9
00:00:31,560 --> 00:00:36,960
Good for you because if this was my first time learning python I wouldn't get this.
10
00:00:36,960 --> 00:00:40,940
Let's go home.
11
00:00:40,940 --> 00:00:50,510
Is that why you expected true evaluated so true because one evaluated to true an empty string.
12
00:00:50,510 --> 00:00:56,740
It goes to one evaluated to false that makes sense because they definitely don't equal each other right.
13
00:00:56,900 --> 00:01:09,050
An empty array doesn't equal to one and a 10 equals ten point zero and then both arrays that are empty
14
00:01:09,110 --> 00:01:10,910
equal to true.
15
00:01:10,910 --> 00:01:21,580
Now the reason I'm showing you here is that the double equals checks for equality or equality of value.
16
00:01:21,710 --> 00:01:28,280
That is if for example the first on true equals to one there's two different types one's an integer
17
00:01:28,400 --> 00:01:33,100
one's a boolean it will convert them into the same type.
18
00:01:33,110 --> 00:01:39,950
In this case this will be converted like this to a boolean value.
19
00:01:40,010 --> 00:01:42,860
And if you remember one is truth.
20
00:01:42,950 --> 00:01:49,250
So this will evaluate to True which is why we get true.
21
00:01:49,310 --> 00:01:58,540
What about the other one well on empty string is false see so it evaluates to false and false doesn't
22
00:01:58,540 --> 00:02:00,880
equal true.
23
00:02:00,880 --> 00:02:01,140
Right.
24
00:02:01,150 --> 00:02:04,590
Because we're checking for equality here.
25
00:02:04,600 --> 00:02:08,440
So one of these gets converted to the other's type.
26
00:02:08,490 --> 00:02:10,800
What about an empty array.
27
00:02:11,010 --> 00:02:20,970
Again an empty array is actually false see so that's not going to equal one a ten equals to a float
28
00:02:21,180 --> 00:02:22,320
of ten point 0.
29
00:02:22,560 --> 00:02:26,400
That gets converted to an integer or float.
30
00:02:26,400 --> 00:02:33,240
And they're going to equal each other and that's an expected behavior and then an empty array well equals
31
00:02:33,240 --> 00:02:34,310
an empty array.
32
00:02:34,350 --> 00:02:42,990
If I add in this array one two three one two three and I click Run I get an invalid syntax because I
33
00:02:42,990 --> 00:02:49,510
have this year let's run that again I get true that makes sense.
34
00:02:49,510 --> 00:02:55,060
Let's change this to one and see what happens if I click Run.
35
00:02:55,080 --> 00:03:01,310
All right still false Now this does get a little tricky right.
36
00:03:01,730 --> 00:03:02,120
Mm hmm.
37
00:03:02,120 --> 00:03:04,210
Should this have evaluated too.
38
00:03:04,210 --> 00:03:12,130
True but now we get false so this doesn't get converted in time vs. what we had here.
39
00:03:12,170 --> 00:03:18,130
Now don't get confused by this because this would be bad code if you're checking something like this.
40
00:03:18,140 --> 00:03:25,070
Well obviously you should be checking two types two of the same types together.
41
00:03:25,340 --> 00:03:33,110
Ideally when you use comparison operators or logical operators like this you're comparing two types
42
00:03:33,140 --> 00:03:39,740
and you're not letting Python do this type conversion and hopefully Python figures it out for us.
43
00:03:39,740 --> 00:03:49,220
But I hope the W quality makes sense because there's another check that we can do which is is and is
44
00:03:49,370 --> 00:03:51,570
well as a keyword in Python.
45
00:03:52,130 --> 00:04:01,080
What happens if we change all these equal signs to is do you think there will be a difference.
46
00:04:01,910 --> 00:04:04,110
Let's have a look.
47
00:04:04,160 --> 00:04:12,690
If I click Run I get false for everything.
48
00:04:12,810 --> 00:04:14,560
So what's the difference here.
49
00:04:14,610 --> 00:04:19,970
Equals checks for the equality in value such as one two three.
50
00:04:20,160 --> 00:04:28,950
Well that's has the same value as one two three in a list is actually checks if the location and memory
51
00:04:29,220 --> 00:04:34,740
where this value is stored is the same.
52
00:04:34,910 --> 00:04:35,960
Let's go through that.
53
00:04:35,960 --> 00:04:43,100
So true is that one note true is not one true is while only true.
54
00:04:43,100 --> 00:04:43,920
Right.
55
00:04:44,090 --> 00:04:45,680
That will be true.
56
00:04:45,680 --> 00:04:49,810
What about string one is that one.
57
00:04:49,810 --> 00:04:50,190
No.
58
00:04:50,230 --> 00:04:55,300
I mean for one to be a shrink that needs to be one.
59
00:04:55,300 --> 00:04:56,460
Right.
60
00:04:56,500 --> 00:05:05,410
Because the one string isn't only in one place in memory it's literally the exact same thing.
61
00:05:05,410 --> 00:05:06,820
What about this list.
62
00:05:06,820 --> 00:05:10,520
As a matter of fact lists two is array empty array.
63
00:05:10,540 --> 00:05:15,550
Is that or is this list a list.
64
00:05:15,550 --> 00:05:19,850
Well if we run this I still get false
65
00:05:22,710 --> 00:05:31,050
and this is a little tricky and also advanced every time I create a list it's added in memory somewhere.
66
00:05:31,080 --> 00:05:41,000
So this is in a location in memory but whenever I create a new list it's created in another location.
67
00:05:41,000 --> 00:05:47,830
So these are two completely different lists that live in different locations in memory.
68
00:05:47,900 --> 00:05:54,110
So it's going to check hey is this in the same memory space same bookshelf as that one.
69
00:05:54,110 --> 00:05:55,540
No that's not it.
70
00:05:56,240 --> 00:06:01,640
But why does this work for things like numbers and strings.
71
00:06:01,640 --> 00:06:09,530
And that's because underneath the hood these are types that are very simple that are in memory but in
72
00:06:09,620 --> 00:06:17,600
one location versus something like a list even though this might be the same list with the same items
73
00:06:18,710 --> 00:06:26,870
because this is a data structure every time we create it it's created in a new location so that even
74
00:06:26,870 --> 00:06:36,470
if we have a variable a that contains this list and by the way this will be the same for all our data
75
00:06:36,470 --> 00:06:41,090
structures like dictionaries sets topples.
76
00:06:41,420 --> 00:06:52,410
If I do B equals this and I check a is that B No they're created in a different memory space.
77
00:06:52,470 --> 00:06:57,740
So this where a points is in a different place than where B points.
78
00:06:58,050 --> 00:07:09,070
But if I do a equals to b I get true because this double equality checks only the values.
79
00:07:09,100 --> 00:07:15,040
Now this is a bit of a hard topic so you might have to watch this video a couple of times you might
80
00:07:15,040 --> 00:07:20,860
have to practice this a few times yourself but just keep in mind the difference between IS and double
81
00:07:20,860 --> 00:07:24,330
equals E is tends to be a little stricter.
82
00:07:24,610 --> 00:07:32,440
You're checking for the exact thing that you're looking for versus equality which checks the value.
83
00:07:32,440 --> 00:07:33,190
All right.
84
00:07:33,280 --> 00:07:34,330
That was a doozy.
85
00:07:34,350 --> 00:07:36,050
Clancy in the next video by.
8319
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.