3.4. Asking Boolean Questions about Sequences¶
The +
and *
operators are not the only operators that work with Python
sequence types, and in this section we will look at using Boolean operators to
ask questions about a sequence.
3.4.1. Comparing Equality¶
The comparison operators also work on strings. To see if two strings are equal you simply write a boolean expression using the equality operator.
In [1]: word = "banana"
In [2]: "Yes" if word == "banana" else "No"
Out[2]: 'Yes'
We can perform tests of equality on a simple tuples as well.
In [3]: a = ("one", "two")
In [4]: b = (1, 2)
In [5]: c = (1, 2)
In [6]: a == b
Out[6]: False
In [7]: b == c