Boolean Expressions
>>>'a' == ('a' or 'b') # Look at parentheses first, so evaluate expression "('a' or
'b')"
# 'a' is a nonempty string, so the first
value is True
# Return that first value: 'a'
>>>'a' == 'a' # the string 'a' is equivalent to the string 'a', so
expression is True
Second case:
>>>'b' == ('a' or 'b') # Look at parentheses first, so evaluate expression "('a' or
'b')"
# 'a' is a nonempty string, so the first
value is True
# Return that first value: 'a'
>>>'b' == 'a' # the string 'b' is not equivalent to the string 'a',
so expression is False
False
Third case
Fourth case:
>>>'b' == ('a' and 'b') # Look at parentheses first, so evaluate expression "('a' and
'b')"
# 'a' is a nonempty string, so the first
value is True, examine second value
# 'b' is a nonempty string, so second
value is True
# Return that second value as result of
whole expression: 'b'
>>>'b' == 'b' # the string 'b' is equivalent to the string 'b', so
expression is True
True
No comments:
Post a Comment