Page 23 - Modular v1.1 Pyhton
P. 23
Logical Operators
Logical operators are used to evaluate and decide.
Python supports the following logical operators:
Operator Name Description Example (x=2) Output
and AND It returns true, if both operands are true. (x < 5) and (x < 10) TRUE
or OR It returns true, if one of the operands is (x < 5) or (x < 2) TRUE
true.
not NOT It reverses the result, returns false, if the not [(x < 5) and (x < FALSE
result is true or vice versa. 10)]
Program 3: To perform all the logical operations.
On running the above program, you will get the following output:
Relational Operator
Relational operators are used to compare the value of the two operands and returns True or
False accordingly. The relational operators are described in the following table:
Example
Operator Name Description Output
(x=8 and y=6)
== Equal It checks if the values of two operands x == y FALSE
are equal or not. If yes, then the condition
becomes true.
Data Types and Operators in Python 21

