ScanSkill

or

This or operator returns the first operand that evaluates to True or the last one if all are False.

Syntax

A or B

Here,

  • A: Required. Any valid object.
  • B: Required. Any valid object.

Note: False, None, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets, and frozensets), these all are interpreted as False. And the rest of others are interpreted as True.

Examples

>>> x or y

Here, first, x is evaluated; if x is true, its value is returned; otherwise, y is evaluated and the resulting value is returned.

>>> 0 or '' or False
False
>>> 1 or '' or False
1
>>> 1 or 'A' or False
1
>>> 1 or 2 or 3
1
>>> b = '' and 'ABCD'
>>> b
'ABCD'
>>> b = 0 and 1
>>> b
1
  • In conditional statements

Return True if one of the statements are True, otherwise, it will return False.

>>> if 13 > 7 or 13 < 10;
...     print("One of the statements is True")
... else:
...     print("None are True")
...
'One of the statements is True.'