Skip to content
← Back to Community
LOGIC OPERATOR "OR"
Profile icon
fatihahbatrisha

CAN ANYBODY HELP ME GIVE AN EXAMPLE OF LOGIC OPERATOR "OR"

Voters
Profile icon
NORMA-ALICIAAL1
Profile icon
0Gabe0
Profile icon
fatihahbatrisha
Comments
hotnewtop
Profile icon
UniqueOstrich18

So the or operator is used like this:
If any of the conditions are true, the operator will return true.

Example:

var1 = True var2 = False if var1 == True or var2 == True: print("One of the conditions were true.") else: print("Both of the conditions were false.")

Output:

One of the conditions were true.

Example 2:

var1 = True var2 = False var3 = False if var1 == True or var2 == True or var3 == True: print("One of the conditions were true.") else: print("Both of the conditions were false.")

Output:

One of the conditions were true.

You can find more information at https://realpython.com/python-or-operator/

If this was helpful, please mark it as the answer.

Profile icon
elonmaks

Hi, @fatihahbatrisha . It came from Arithmetic of binary system.

Truth Table:
#----------------------

A B F

#----------------------

1 1 1

1 0 1

0 1 1

0 0 0

#----------------------

For example in code:

a = 1
b = 1

it gives you True, because at least one, a or b is equals to 1 which is True. OR operator doesn't require two True's here. It needs only one to make it True.

a = 1
b = 0

it gives you True, because also at least one, a or b is equals to 1 which is True. OR operator doesn't require two True's here. It needs only one to make it True.

a = 0
b = 1

it gives you True, because also at least one, a or b is equals to 1 which is True. OR operator doesn't require two True's here. It needs only one to make it True.

a = 0
b = 0

it gives you False. because it doesn't have any 1 value here, which is True. But it has 0 and here is not at least one 1, so what it gives you then? Right!! It's a False.

So take a look at the code below:

When you are using this OR operator it means you want to make if statement switching to True or False. It's like switching the lamp. You can manage when the lamp can be switched and when not.

True is Turn on.
False is Turn off.

if a or b:
print("True")
else:
print("False")

fatihahbatrisha

So what differencies between AND operator and OR operator is that AND operator for making any statement to True requires only and only two 1's , which is True. Therefore it would be like:

if 1 and 1:
print("True")
else:
print("False")

if 1 and 0:
print("True")
else:
print("False")

if 0 and 1:
print("True")
else:
print("False")

if 0 and 0:
print("True")
else:
print("False")

fatihahbatrisha2