Logical Operators in Python!

Article #013

In today's article, we will discuss the logical operators in Python. There are three logical operators namely AND, OR & NOT. We will try to understand these with the help of a simple use case.

AND Operator It provides the output as True when both the conditions under consideration are True. The below table is a summary of results obtained by using AND operator.

True AND False will yield False
False AND False will yield False
False AND True will yield False
True AND True will yield True

OR Operator Unlike the AND operator, it provides the output as True when any one of the two conditions under consideration is True. The below table is a summary of results obtained by using OR operator.

True OR False will yield True 
False OR False will yield False
False OR True will yield True 
True OR True will yield True

NOT Operator It simply provides the output which is the opposite of the input. E.g. NOT operator on False will give True and vice-versa.

Below is a simple use case of these operators.

Attendance = 70
Assignment_submitted = 40
print(f"Attendance criteria met? : {Attendance >= 75}")
print(f"Assignment criteria met? : {Assignment_submitted >= 70}")
if attendance >= 75 and assignment_submitted >= 70:
    print("The student is eligible to appear in the final exam")
else:
    print("The student is not eligible")

The output of the above code is 

Attendance criteria met? : False
Assignment criteria met? : False
The student is not eligible

In the above example, we have simply tried to know whether the student is eligible to appear in the exam or not. Hope this short explanation is helpful to understand the basic concept of Logical operators in Python.