-: All right.
In this video I'm gonna try and trick you.
I want you to look at these expressions
where I'm checking for equality, right?
I'm saying,
"Hey does True == 1; does empty string == 1
do two arrays equal, that are empty, equal well each other?
Now, pause the video here and try to guess what the outcomes
of this are going to be.
Ready?
By the way, if you get a hundred percent on this,
well good for you
because if this was my first time learning Python
I wouldn't get this.
Let's go.
Hmm? Is that why you expected?
True evaluated, so
True == 1 evaluated to True?
An empty string == 1 evaluated to False.
That makes sense
because they definitely don't equal each other, right?
An empty array doesn't equal to 1
and a 10 == 10.0
and then both arrays that are empty equal to True.
Now, the reason I'm showing you here is
that the double equals checks
for equality or equality of value.
That is if, for example,
the first one, True == 1, there's two different types.
One's an integer, one's a bulleon
it will convert them into the same type.
In this case, this will be converted
like this to a bulleon value.
And if you remember, one is truthy.
So this will evaluate to True, which is why we get True.
What about the other one?
Well, an empty string is falsey, so it evaluates to False.
And False doesn't equal True, right?
Because we're checking for equality here.
So one of these gets converted to the other's type.
What about an empty array?
Again, an empty array is actually falsey
so that's not going to == 1.
A 10 equals to a float of 10.0.
That gets converted to an integer or float
and they're going to equal each other,
and that's an expected behavior.
And then an empty array will equals an empty array.
If I add in this array '1, 2, 3', '1, 2, 3',
and I click run, I get an invalid syntax.
Oh, because I have this here.
Let's run that again.
I get True.
That makes sense.
Let's change this to 1 and see what happens.
If I click run, all right.
Still False.
Now this does get a little tricky, right?
Like, hmm, should this have evaluated to True?
But no, we get False, so this doesn't get converted
in type versus what we had here.
Now, don't get confused by this
because this would be bad code
if you're checking something like this.
Well, obviously you should be checking two types,
two of the same types together.
Ideally, when you use comparison operators
or logical operators like this, you're comparing two types
and you're not letting Python do this type conversion.
And hopefully Python figures it out for us.
But I hope the double equality makes sense
because there's another check that we can do,
which is, is and is, well, is a keyword in Python.
What happens if we change all these equal signs to is?
Do you think there would be a difference?
Let's have a look.
If I click run:
I get False for everything.
Hmm.
So what's the difference here?
Equals checks for the equality in value such as 1, 2, 3.
Well, that's has the same value as 1, 2, 3
in a list.
"is" actually checks if the location and memory
where this value is stored is the same.
Hmm, let's go through that.
So True is that 1.
No, True is not 1.
True is well, only True, right?
That will be True.
What about string one?
Is that 1?
No.
I mean, for 1 to be a string, that needs to be 1 right?
Because the one string isn't only in one place
in memory, it's literally the exact same thing.
What about this list?
As a matter of fact, let's do, is array empty array?
Is that, or is this list a list?
Well, if we run this, I still get False.
Hmm.
And this is a little tricky and also advanced.
Every time I create a list, it's added in memory somewhere.
So this is in a location in memory, but whenever
I create a new list, it's created in another location.
So these are two completely different lists that live
in different locations in memory.
So it's going to check,
"Hey, is this in the same memory space?
Same bookshelf as that one?
Nope, that's not it."
Wait, why this work for things like numbers and strings?
And that's because underneath the hood
these are types that are very simple that are in memory
but in one location.
Versus something like a list.
Even though this might be the same list with the same items
because this is a data structure,
every time we create it, it's created in a new location
so that even if we have a variable A that contains this list
and by the way, this will be the same
for all our data structures, like dictionaries, sets, tops.
If I do B equals this and I check A, is that B?
Nope. They're created in a different memory space.
So this where A points is in a different place
than where B points,
but if I do A == B, I get true
because this double equality checks only the values.
Now, this is a bit of a hard topic,
so you might have to watch this video a couple times.
You might have to practice this a few times yourself,
but just keep in mind the difference between
is and double equals, i-is tends to be a little stricter.
You're checking for the exact thing that you're looking
for versus equality, which checks the value.
All right.
Whew. That was a doozy.
I'll see you in the next video.
Bye-bye.