Compare Values (Solution)
00:00
Okay, so the first conditional expression was 1 <= 1
, and I would expect that to be True
. Let’s test it out. Yep, it’s True
. It’s just a little training to get you warmed up.
00:15
Next one is 1 != 1
. That sounds False
to me because those are the same values. So this is False
. The next one is similar.
00:26
It says 1 != 2
. In that case, that looks like it is True
because it’s two different integers. So that is True
.
00:36
And we have another one. Now it’s strings. This one reads the string "good"
is different from the string "bad"
. It does not equal the string "bad"
.
00:44
That sounds True
to me. Yep, that is True
as well.
00:49
Then we have another one that reads the string "good"
in lowercase is not the same as the string "Good"
that is capitalized. And keep in mind that something like this is true even though it’s the same word for us reading it.
01:03
Those are two different strings for Python because the case of characters matters when Python evaluates strings. The lower "g"
is not the same as the uppercase "G"
. So I expect that to be True
,
01:15
and it is. And then the last one was that the integer 123
is equal to the string "123"
. Now these are two different types, so they’re not equal to each other, so I expect that to be False
. All right, so that’s a quick training session, and it worked out.
01:36
And here are our solutions put back onto the slide. I’m using like a little green check mark for True
and an X for False
. And here’s the solutions. 1 <= 1
is true. 1 != 1
is false. 1 != 2
is true.
01:53
The string "good"
does not equal the string "bad"
is True
. String lowercase "good"
does not equal the string capitalized "Good"
is also True
.
02:00
And the end, integer 123
is equal to the string “123”`. That is False
. All right, let’s move on to the next exercise.
Become a Member to join the conversation.