Logical Operators
These operators are used to test if a particular conditional statement is true or false. They include,
NOT, OR, and AND. However, there are rules that apply to these operators for them to either
return true or false. These rules are:
A NOT operator will return True only when the operand is false
An OR operator returns true if one of the operands is true
The AND operator returns true when both the operands are true
Here is an example. We will use number1 and number2 to represent true and false respectively.
number 1 = True
number2 = False
print ((“NOT number2 is: ” NOT number2))
print ((“number1 OR number2 is: ” number1 OR number2))
print ((“number1 AND number2 is: ” number1 AND number2))
The output will be as follow
True
True
False
Do'stlaringiz bilan baham: |