Logical OR

The logical operator OR returns False only if both the operands are False else it returns True. It is a binary operator, which means to return some value, it has to be operated between two operators (i.e, two operators are required)

Truth Table:

Operator A Operator B Logical OR Result
True True True
True False True
False True True
False False False

Example 1:

Python3




a = 10
b = -5
  
if a < 0 or b < 0:
  print("Their product will be negative")
else:
  print("Their product will be positive")


Output:

Their product will be negative

Example 2:

Python3




a = 10
  
if (a == 0 or "w3wiki"):
  print("Is Awesome")
else:
  ("Try Again!")


Output:

Is Awesome

Here, in the OR Logical operator, even if the first expression evaluated is false while using and operator, then also the further expressions are evaluated. Also, any string is always considered a true statement. In the above example, the first statement is false but then too, it will evaluate the second statement because it returns False only if both the operands are False and since the string is considered as True statement, thus, it will be evaluated and the below print statement will be printed.

Python 3 – Logical Operators

Logical Operators are used to perform certain logical operations on values and variables. These are the special reserved keywords that carry out some logical computations. The value the operator operates on is known as Operand. In Python, they are used on conditional statements (either True or False), and as a result, they return boolean only (True or False). They are used to combine conditional statements

There are following logical operators supported by Python language:

  • Logical AND
  • Logical OR
  • Logical NOT

Similar Reads

Logical AND

Logical operator AND returns True only if both the operands are True else it returns False. It is a binary operator, which means to return some value, it has to be operated between two operators (i.e, two operators are required)...

Logical OR

...

Logical NOT

...