Python Learning Series · @onlysamarrr · Day 5 / 30

Day 5: Comparison and Logical Operators

Day 5 teaches comparison and logic. Comparison operators (==, !=, >, <, >=, <=) return True or False, and and, or and not combine conditions. Note: = assigns, == compares.

Phase: Beginner · Reels: 21/450 – 25/450

Quick Answer

Day 5 teaches comparison and logic. Comparison operators (==, !=, >, <, >=, <=) return True or False, and and, or and not combine conditions. Note: = assigns, == compares.

What You Will Learn

Code

x = 7
print(x == 7)
print(x != 7)
print(x > 5 and x < 10)
print(x < 5 or x > 10)
print(not (x > 10))
print(5 < x < 10)
print(bool(0), bool(""), bool("0"), bool([]))

Output

True
False
True
False
True
True
False False True False

Code Explained, Line by Line

  1. x == 7 compares x with 7 and returns True or False. x = 7 only assigns the value.
  2. and is True only when both sides are True. or is True when at least one side is True.
  3. not flips a value: not True is False.
  4. Python allows chaining: 5 < x < 10 means 5 < x and x < 10 together.
  5. Falsy values are 0, 0.0, "", [], {}, set() and None. Everything else is truthy, so bool("0") is True.
Common Mistake: Writing if x = 5: raises a SyntaxError. Conditions must use ==, not =.

Real-Life Use

Login checks, age gates and discount rules are all built from comparison and logical operators.

Practice Task: Decide True or False for 10 > 5 and 10 < 20, and for not (3 == 3).

Test Yourself — MCQs

Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.

Q1. Which operator compares two values?

Q2. What is True and False?

Q3. What is bool("")?

Today's 5 Reels (from the 90-Day Plan Excel)

21/450Concept== != > < operators
22/450Live demoand, or, not live
23/450Common mistake= vs == galti
24/450QuizQuiz: True ya False?
25/450Interview / real lifeInterview: truthy aur falsy values

Note: In the Excel file, two Day 5 reel titles were blank, so those two titles were taken from the example Roadmap PDF for the same day, topic and order. All other titles come exactly from the Excel file.

← Day 4Day 6 →