Logical Operators

Logical Operators in Python are used to combine multiple conditions and return a result as True or False.

Real-Life Example

Logical operators are like decisions in real life:

  • If you have a ticket AND ID → you can enter
  • If you have money OR card → you can pay
  • If it is NOT raining → you can go outside

Explanation

These operators help in decision-making by checking more than one condition at the same time.

They are commonly used in:

  • if statements
  • Loops
  • Real-life problem solving

They always return a Boolean value (True/False).

Types of Logical Operators

  • and → Returns True if both conditions are True
  • or → Returns True if at least one condition is True
  • not → Reverses the result (True → False, False → True)

Example Program 1

a = 10

print(a > 5 and a < 20)
print(a > 15 or a < 20)
print(not(a > 5))

Output:

True
True
False

Example Program 2

age = 18
has_id = True

if age >= 18 and has_id:
    print("Eligible to vote")
else:
    print("Not eligible")

Output:

Eligible to vote

Explanation

  • age >= 18 → checks if the person is 18 or older
  • has_id → checks if the person has an ID proof
  • and → both conditions must be True

Common Beginner Mistakes

  •  Confusing and / or
  •  Forgetting brackets
  •  Misunderstanding True/False
  •  Wrong condition combinations

Key Points 

  • Logical operators combine conditions
  • They return True or False
  • Used in decision-making programs
  • Important for building logic in Python

Tips 

  • Use and when both conditions must be true
  • Use or when at least one condition is enough
  • Use not to reverse results
  • Practice using if conditions

Check your knowledge

Quickly verify what you've learned from this tutorial.

Question 1

What do logical operators return?

Logical operators return Boolean values.

Question 2

Which operator returns True only if both conditions are True?

and requires both conditions to be True.

Question 3

What will be the output of the following code?

print(True or False)

Both are not True, so result is False.

Question 4

What is the output?

print(False or True)

or returns True if at least one condition is True.

Question 5

What is the output?

a = 10
print(a > 5 and a < 8)

First is True but second is False, so result is False.

Congratulations!

You've successfully mastered the knowledge check for "Logical Operators."

For more questions and practice, click the link below:

Practice More Questions
Previous Topic Comparison Operators Next Topic Conditional Statements