- [Instructor] In this video, I'd like to demonstrate
the comparison operators for strings.
But first, I'd like to just remind you
that when you're doing string comparisons in Python,
it's lexicographical comparisons,
that is the underlying numeric values
of the characters are what are being compared.
So you may recall that we introduced the ord function
previously, the built-in function ord,
which simply returns for a character
the corresponding numeric value.
So here we have the capital letter A
and the lowercase letter a
and we just wanted to show you
that the capital letter has a smaller value
than the lowercase letter,
because that's going to affect the comparisons
that we're going to do in the next several expressions.
So you can compare any two strings
using the comparison operators, the equality,
inequality, less than, less than or equal,
greater than, or greater than or equal to operators.
In this case, yes it's the same word,
but one of them is spelled with an uppercase letter
and one with a lowercase letter, so these are not equal.
And of course, correspondingly,
if I change that to a not equals operator,
we will, in fact, get true.
Now if I change that operator to a less than sign
because a capital O is less than a lowercase o,
this will be true, and so will, of course,
less than or equal because it's still less than
in that case.
If I change the operator to a greater than sign,
capital O is not greater than lowercase o
in terms of as key values,
so capital a is less than lowercase A,
capital o will be less than lowercase O as well.
Therefore, this will result in false,
as will the greater than or equal operator.