Conditional Statements in Python
Logical Operators
The logical operators are as follows:
not (negation),
and (and),
or (or).
Except for the
not operator, which is
unary (operates on a single operand), the other logical
operators are
binary (operate on two operands). The operands can be of any type, such as boolean, integer, real, etc.
The result will always be a boolean value –
True or
False.
EXAMPLES
Analyze the result of the following logical expressions by running the program:
DETAILS
The logical negation operator (
not) works as follows: if the operand is a value different from
0 or
True, the result is
False; in any other case, the result is
True.
The logical and operator (
and). The way the result is obtained can be observed from the table below:
If both operands are different from
False, the result is
True; otherwise, it is
False.
The logical or operator (
or). The way the result is obtained can be observed from the table below:
The rule here is simple: if one of the operands is
True, the result is
True; otherwise, the result is
False.
Therefore...
The decisions made are based on evaluating expressions that have
a logical result -
Yes or
No. Let's continue.
Run the program and then proceed to the next page.