Logical Operators
Files associated with this lesson:
Logical Operators.ipynb
Logical Operators¶
These operators are used to "concatenate" other operations. These should read naturally in english. Let's see a few examples.
and
operator¶
All the operations should be true to final result to be true:
In [1]:
user_is_active = True
age = 21
if user_is_active is True and age > 18:
print("You can order")
else:
print("You're not allowed here")
or
operator¶
At least one of the operators must be true for the result to be true.
In [2]:
food = "hamburger"
if food == "hamburger" or food == "spaghetti":
print("I like this food!")
else:
print("Hmm... We'll see...")
In [ ]: