Strings (except an empy string) will always evaluate to True
when they are evaluated as a boolean. While evaluating with or/and
both will return True
, but there is a little difference between them:
print 'a' or 'b' # Output: a
print 'a' and 'b' # Output: b
or
: will return the first string
and
: will return the last string
When you do
if ('a' or 'b') in L:
, it will check 'a' or 'b'
which is 'a'
and then check if 'a'
is in L
. Something similar happens with the other cases (based on what I explained before).
So when you do
if ('e' or 'a') in L:
, 'e' or 'a'
will evaluate to 'e'
and therefore it will print 'No Sorry'
, because 'e'
is not in L
.
What you must do is compare whether elements are in the list separately:
if 'a' in L or 'b' in L:
if 'a' in L or 'd' in L:
if 'e' in L or 'd' in L:
if 'e' in L or 'a' in L: