Logical Operators
Logical operators work when we got multiple conditions (And and Or)
There are following logical operators supported by Python language. Assume variable a holds 10 and variable b holds 20 then −
Operator | Description | Example |
---|---|---|
and Logical AND | If both the operands are true then condition becomes true. | (a and b) is true. |
or Logical OR | If any of the two operands are non-zero then condition becomes true. | (a or b) is true. |
not Logical NOT | Used to reverse the logical state of its operand. | Not(a and b) is false. |
In the next example, there is an application to buy a house, the person needs a high income AND good credit. If both conditions are true, the applicant is eligible for a loan
Both conditions need to be True..
now check what happens if either of them is false
We can also apply with the OR statement, it means that either way, in ONE of them is true, it's approved
AND: Both True
OR: Ar least one of them must be true
AND NOT
We will ad the statement has a bankrupt record
When you use this condition one has to be True and the other one has to be False
Logical Operators
Reviewed by ohhhvictor
on
May 05, 2019
Rating:
No comments: