Page 90 - Digicode_AI_class_7
P. 90
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 true. (x < 5) or (x < 2) TRUE
not NOT It reverses the result, returns false, if the not [(x < 5) and (x < 10)] FALSE
result is true or vice versa.
Program: 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.
!= Not equal It checks if the values of two operands are x != y TRUE
equal or not. If the values are not equal, then
the condition becomes true.
88 DigiCode AI-VII

