By Hemanta Sundaray on 2021-09-06
We use logical (aka boolean) operators - and, or & not - in Python to make multiple comparisons at the same time.
revenue = 150
profit = 15
if revenue > 100 and profit > 10:
print("You will get a bonus.")
else:
print("You are not eligible for bonus.")
# Output
# You will get a bonus.
education = "BTech"
programming_experience = 1
if education == 'BTech' or programming_experience >= 2:
print("You can apply to the advanced machine learning program.")
# Output
# You can apply to the advanced machine learning program.
Unlike and and or, the not operator operates only on one Boolean value or expression. The not operator simply evaluates to the opposite Boolean value.
print(not False)
# True
print(not True)
# False