1
00:00:01,310 --> 00:00:04,250
All right, in this video, I'm going to try and trick you.

2
00:00:05,080 --> 00:00:10,840
I want you to look at these expressions where I'm checking for equality, right?

3
00:00:10,990 --> 00:00:13,150
I'm saying, hey, does true equal one?

4
00:00:13,180 --> 00:00:18,750
Does empty string equal one due to race equal that are empty.

5
00:00:18,760 --> 00:00:20,410
Equal well, each other.

6
00:00:21,630 --> 00:00:26,790
Now, pause the video here and try to guess what the outcomes of this are going to be.

7
00:00:28,140 --> 00:00:33,690
Ready, by the way, if you get one hundred percent on this, well, good for you, because if this

8
00:00:33,690 --> 00:00:36,420
was my first time learning Python, I want to get this.

9
00:00:36,870 --> 00:00:37,410
Let's go.

10
00:00:39,750 --> 00:00:42,420
Hmm, is that what you expected?

11
00:00:45,780 --> 00:00:52,540
Evaluated so true because one evaluated to true an empty string equals to one evaluated to false.

12
00:00:53,130 --> 00:00:56,040
That makes sense because they definitely don't equal each other.

13
00:00:56,040 --> 00:00:56,270
Right.

14
00:00:56,790 --> 00:00:59,970
An empty array doesn't equal to one.

15
00:01:01,770 --> 00:01:05,520
And a 10 equals ten point zero.

16
00:01:07,390 --> 00:01:10,010
And then both the rays that are empty, equal to true.

17
00:01:10,840 --> 00:01:20,570
Now, the reason I'm showing you here is that the double equals checks for equality or equality of a

18
00:01:20,590 --> 00:01:21,040
value.

19
00:01:21,700 --> 00:01:26,980
That is, if, for example, the first one true equals to one, there's two different types.

20
00:01:26,980 --> 00:01:33,020
One's an integer, one's a Bolian, it will convert them into the same type.

21
00:01:33,040 --> 00:01:39,910
In this case, this will be converted like this to a boolean value.

22
00:01:39,940 --> 00:01:42,880
And if you remember, one is Truthy.

23
00:01:42,890 --> 00:01:47,920
So this will evaluate to true, which is why we get true.

24
00:01:49,250 --> 00:01:50,940
What about the other one?

25
00:01:51,860 --> 00:02:01,160
Well, an empty string is falsey, so it evaluates to false and false doesn't equal true, right.

26
00:02:01,160 --> 00:02:04,180
Because we're checking for equality here.

27
00:02:04,520 --> 00:02:07,520
So one of these gets converted to the other type.

28
00:02:08,420 --> 00:02:10,310
What about an empty array?

29
00:02:10,880 --> 00:02:15,380
Again, an empty array is actually falsey.

30
00:02:16,610 --> 00:02:24,830
So that's not going to equal one a 10 equals to a float of ten point zero that gets converted to an

31
00:02:24,830 --> 00:02:27,980
integer or float and they're going to equal each other.

32
00:02:27,980 --> 00:02:29,840
And that's an expected behavior.

33
00:02:30,230 --> 00:02:35,810
And then an empty array well, equals an empty array if I add in disarray.

34
00:02:35,810 --> 00:02:39,140
One, two, three, one, two, three.

35
00:02:39,620 --> 00:02:40,820
And I click run.

36
00:02:41,150 --> 00:02:43,560
I get an invalid syntax because I have this year.

37
00:02:43,610 --> 00:02:44,480
Let's run that again.

38
00:02:48,510 --> 00:02:49,290
That makes sense.

39
00:02:49,470 --> 00:02:52,920
Let's change this to one and see what happens if I click run.

40
00:02:54,990 --> 00:02:56,580
All right, still false.

41
00:02:57,760 --> 00:03:05,110
Now, this does get a little tricky, Ray, like, hmm, should this have evaluated to true, but no,

42
00:03:05,110 --> 00:03:11,330
we get false so this doesn't get converted in tight versus what we had here.

43
00:03:12,100 --> 00:03:17,420
Now, don't get confused by this because this would be bad code if you're checking something like this.

44
00:03:18,070 --> 00:03:24,430
Well, obviously, you should be checking two types, two of the same types together.

45
00:03:25,240 --> 00:03:33,130
Ideally, when you use comparison operators or logical operators like this, you're comparing two types

46
00:03:33,130 --> 00:03:36,490
and you're not letting Python do this type conversion.

47
00:03:36,490 --> 00:03:38,830
And hopefully Python figures it out for us.

48
00:03:39,700 --> 00:03:47,770
But I hope the double quality makes sense because there's another check that we can do, which is is

49
00:03:48,460 --> 00:03:51,350
and is well is a key word in Python.

50
00:03:52,090 --> 00:03:57,340
What happens if we change all these E cosigns to is.

51
00:03:58,870 --> 00:04:00,790
Do you think there would be a difference?

52
00:04:01,810 --> 00:04:02,500
Let's have a look.

53
00:04:04,060 --> 00:04:05,260
If I click, run.

54
00:04:07,560 --> 00:04:10,200
I get false for everything.

55
00:04:12,720 --> 00:04:19,920
So what's the difference here equals checks for the equality in value, such as one, two, three?

56
00:04:20,100 --> 00:04:28,380
Well, that's has the same value as one, two, three in a list is actually checks if the location in

57
00:04:28,380 --> 00:04:32,520
memory where this value is stored is the same.

58
00:04:34,890 --> 00:04:35,650
Let's go through that.

59
00:04:35,880 --> 00:04:42,960
So true is that one no, true is not one true is well, only true.

60
00:04:43,020 --> 00:04:43,470
Right?

61
00:04:44,040 --> 00:04:45,150
That will be true.

62
00:04:45,600 --> 00:04:46,170
What about.

63
00:04:47,490 --> 00:04:49,760
String one is that one?

64
00:04:49,820 --> 00:04:55,710
No, I mean, for one to be a string, that needs to be one, right?

65
00:04:56,460 --> 00:05:04,500
Because the one string isn't only in one place in memory, it's literally the exact same thing.

66
00:05:05,340 --> 00:05:06,600
What about this list?

67
00:05:06,780 --> 00:05:15,030
As a matter of fact, let's do is array empty array is that or is this list a list?

68
00:05:15,480 --> 00:05:16,710
Well, if we run this.

69
00:05:18,180 --> 00:05:19,830
I still get false.

70
00:05:22,600 --> 00:05:31,040
And this is a little tricky and also advanced every time I create a list, it's added in memory somewhere.

71
00:05:31,060 --> 00:05:37,120
So this is in a location, in memory, but whenever I create a new list.

72
00:05:38,280 --> 00:05:46,560
It's created in another location, so these are two completely different lists that live in different

73
00:05:46,560 --> 00:05:47,540
locations in memory.

74
00:05:47,820 --> 00:05:53,820
So it's going to check, hey, is this in the same memory space, same bookshelf as that one?

75
00:05:54,030 --> 00:05:55,340
Nope, that's not it.

76
00:05:56,190 --> 00:06:00,670
But why does this work for things like numbers and strings?

77
00:06:01,530 --> 00:06:09,180
And that's because underneath the hood, these are types that are very simple, that are in memory,

78
00:06:09,180 --> 00:06:16,650
but in one location versus something like a list, even though this might be the same list with the

79
00:06:16,650 --> 00:06:17,580
same items.

80
00:06:18,690 --> 00:06:26,520
Because this is a data structure, every time we create it, it's created in a new location so that

81
00:06:26,520 --> 00:06:29,730
even if we have a variable AI that contains.

82
00:06:30,830 --> 00:06:32,150
This list.

83
00:06:33,700 --> 00:06:40,690
And by the way, this will be the same for all our data structures like dictionaries, sets, tuples,

84
00:06:41,320 --> 00:06:47,230
if I do B equals this and I check A, is that B?

85
00:06:48,780 --> 00:06:56,160
No, they're created in a different memory space, so this where eight points is in a different place

86
00:06:56,190 --> 00:07:00,450
than where B points, but if I do A equals to B.

87
00:07:02,550 --> 00:07:05,850
I get true because this double quality checks.

88
00:07:06,830 --> 00:07:07,850
Only the values.

89
00:07:09,060 --> 00:07:14,820
Now, this is a bit of a hard topic, so you might have to watch this video a couple of times, you

90
00:07:14,820 --> 00:07:17,100
might have to practice this a few times yourself.

91
00:07:17,580 --> 00:07:21,360
But just keep in mind the difference between is and double equals.

92
00:07:21,390 --> 00:07:23,750
E is tends to be a little stricter.

93
00:07:24,540 --> 00:07:31,510
You're checking for the exact thing that you're looking for versus equality, which checks the value.

94
00:07:32,340 --> 00:07:32,790
All right.

95
00:07:33,240 --> 00:07:34,050
That was a doozy.

96
00:07:34,430 --> 00:07:35,410
See you in the next video.

97
00:07:35,730 --> 00:07:36,090
Bye bye.
