All right, in this video, I'm going to 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 equal one?
Does empty string equal one due to race 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 one hundred percent on this, well, good for you, because if this
was my first time learning Python, I want to get this.
Let's go.
Hmm, is that what you expected?
Evaluated so true because one evaluated to true an empty string equals to one evaluated to false.
That makes sense because they definitely don't equal each other.
Right.
An empty array doesn't equal to one.
And a 10 equals ten point zero.
And then both the rays 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 a
value.
That is, if, for example, the first one true equals to one, there's two different types.
One's an integer, one's a Bolian, it will convert them into the same type.
In this case, this will be converted like this to a boolean 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 type.
What about an empty array?
Again, an empty array is actually falsey.
So that's not going to equal one a 10 equals to a float of ten point zero 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 well, equals an empty array if I add in disarray.
One, two, three, one, two, three.
And I click run.
I get an invalid syntax because I have this year.
Let's run that again.
That makes sense.
Let's change this to one and see what happens if I click run.
All right, still false.
Now, this does get a little tricky, Ray, like, hmm, should this have evaluated to true, but no,
we get false so this doesn't get converted in tight 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 quality makes sense because there's another check that we can do, which is is
and is well is a key word in Python.
What happens if we change all these E cosigns to is.
Do you think there would be a difference?
Let's have a look.
If I click, run.
I get false for everything.
So what's the difference here equals checks for the equality in value, such as one, two, three?
Well, that's has the same value as one, two, three in a list is actually checks if the location in
memory where this value is stored is the same.
Let's go through that.
So true is that one no, true is not one true is well, only true.
Right?
That will be true.
What about.
String one is that one?
No, I mean, for one to be a string, that needs to be one, 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.
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.
But why does 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 AI that contains.
This list.
And by the way, this will be the same for all our data structures like dictionaries, sets, tuples,
if I do B equals this and I check A, is that B?
No, they're created in a different memory space, so this where eight points is in a different place
than where B points, but if I do A equals to B.
I get true because this double quality checks.
Only the values.
Now, this is a bit of a hard topic, so you might have to watch this video a couple of times, you
might have to practice this a few times yourself.
But just keep in mind the difference between is and double equals.
E 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.
That was a doozy.
See you in the next video.
Bye bye.