Page 96 - Information_Practice_Fliipbook_Class11
P. 96
4.4.4 Logical Operators
A logical value is True or False. The logical operators yield True or False, depending upon the value of logical
operands on either side. A value other than 0 and None evaluates to True while zero evaluates to False. Therefore,
1, "bb", and -1 are interpreted as True but 0 and None are interpreted as False. There are three logical
operators: and, or, and not. Note that all three operators are keywords and are used in lowercase only. Further, in
an expression, the precedence of the operators in decreasing order is: not, and, or. These operators may be used to
express relationships between relational expressions. For detailed description of these operators, see Table 4.4: Logical
Operators.
Table 4.4: Logical Operators
(Assume the value of a, b, and c to be 10, 5, and -2, respectively for computations in the table)
Operator Explanation Examples
and It yields True if both the operands yield True, and >>> True and True
False otherwise. True
>>> True and False
False
>>> a > b and b > c
True
>>> a < b and b > c
False
>>> a < b and b < c
False
or It yields True if either of the two operands yields >>> True or True
True, and False otherwise. True
>>> False or True
True
>>> False or False
False
>>> a > b or b > c
True
>>> a < b or b > c
True
>>> a < b or b < c
False
not Not True yields False and Not False yields >>> not True
True. False
>>> not False
True
>>> not a > c
False
>>> test = 0
>>> not test
True
82 Touchpad Informatics Practices-XI

