##### LOGIC OPERATOR "OR"

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

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")

# 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")

So the

`or`

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

Example:

Output:

Example 2:

Output:

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

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