🐍 Python for kids · Class 6 · Lesson 2 of 18 · Free
Comparison Operators – True or False?
⏱ About 25 minutes · ▶ run real Python here — nothing to install · no sign-in
In this lesson you will
- Use the six comparison operators and predict their True or False answers.
- Write range checks like 10 <= age <= 14 in one line.
- Compare strings safely and test membership with in.
Is Virat's score more than Rohit's? Is the password correct? Are your marks at least 33? Every decision in a program starts with a comparison. Each one gives a simple answer: True or False.
What are comparison operators in Python?
A comparison operator compares two values and gives back a bool. A bool is either True or False.
There are six of them. == means equal and != means not equal.
> means greater and < means less. >= and <= also allow the two values to be equal.
You can print a comparison directly. Python shows you its answer.
Watch the edge cases: 48 >= 48 is True, but 48 > 48 is False.
▶runs = 482print(runs == 50)3print(runs != 50)4print(runs > 45)5print(runs < 45)6print(runs >= 48)7print(runs <= 47)
No variables yet.
▌✏️ Change this code and run it yourself
False True True False True False
What is the difference between = and == in Python?
One = means "store this value". It puts a value into a variable.
Two == means "are these equal?". It asks a question and gives True or False.
Mixing them up is one of the most common beginner bugs. Read == aloud as "is equal to".
▶pin = 43212entered = 43213match = pin == entered4print("PIN correct?", match)5print(type(match))
No variables yet.
▌✏️ Change this code and run it yourself
PIN correct? True <class 'bool'>
💡 In match = pin == entered, Python first checks pin == entered. Then it stores True or False in match.
How do I check if a number is between two values?
Python lets you chain comparisons, just like in maths. 10 <= age <= 14 means age is from 10 to 14.
It is the same as age >= 10 and age <= 14, but shorter and easier to read.
Here the program decides which inter-school sports group a student joins.
Your age: 12 You are in the Under-14 group.
Can I compare strings in Python?
Yes. == checks if two strings are exactly the same, letter by letter.
Capital letters matter. "Delhi" and "delhi" are different strings to Python.
To ignore capitals, change both sides with .lower() first. < and > compare strings in dictionary order.
▶city = "Delhi"2print(city == "delhi")3print(city.lower() == "delhi")4print("apple" < "banana")5print("Zebra" < "apple")
No variables yet.
▌✏️ Change this code and run it yourself
False True True True
💡 "Zebra" < "apple" is True because every capital letter comes before every small letter in Python's order.
How do I check if something is in a list or string?
The in operator asks: is this item inside that group? It also gives True or False.
It works on lists, and on strings too. not in asks the opposite question.
This makes checks like "is it a vowel?" very short.
Your name: Sara Sara is on the toppers list! True True
Can I store the result of a comparison in a variable?
Yes. A True or False value can be saved like any other value. Such variables often start with is_ or has_.
This gives each check a clear name. The final if then reads almost like English.
Named checks also help when you hunt for bugs. You can print each one and see which failed.
Pass: True Attendance ok: True Promoted to the next class!
🤔 Predict the output
Think like Python: read the code and choose what it prints. You get the reason straight away.
Question 1. What does this print?
a = 7 b = 7.0 print(a == b, a != b)
Question 2. What does this print?
x = 15 print(10 < x < 15) print(10 < x <= 15)
Question 3. What does this print?
word = "Mango"
print("m" in word, "M" in word)🧩 Your challenge
Online ride booking! Ask for the rider's age and height in cm. A rider may go only if age is from 8 to 60 and height is at least 120. Print True or False for each check, then print the final decision.
Age: 11 Height in cm: 115 Age ok: True Height ok: False Sorry, not allowed.
⚠️ Common mistakes (and how to fix them)
❌ Wrong
score = 100
if score = 100:
print("Century!")SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
✅ Right
score = 100
if score == 100:
print("Century!")A single = stores a value. To ask a question inside if, you need two equal signs ==.
❌ Wrong
answer = input("Capital of India? ")
if answer == "New Delhi":
print("Correct!")
else:
print("Wrong!")No error message – but the right answer typed in small letters is marked Wrong!
✅ Right
answer = input("Capital of India? ")
if answer.lower() == "new delhi":
print("Correct!")
else:
print("Wrong!")String comparison is case-sensitive. Change the answer to lower case first, then compare with a lower-case string.
❌ Wrong
age = input("Age: ")
if age >= 18:
print("You can vote.")TypeError: '>=' not supported between instances of 'str' and 'int'
✅ Right
age = int(input("Age: "))
if age >= 18:
print("You can vote.")input() always gives a string. Python cannot say if a string is bigger than a number, so convert it with int().
📌 Remember
- Comparison operators give a bool: True or False.
- = stores a value, while == asks if two values are equal.
- Chained checks like 8 <= age <= 10 test a range in one line.
- String comparison is case-sensitive; use .lower() to ignore capitals.
- in and not in check if an item is inside a list or string.
Finished the quiz and the challenge?
Questions students ask
What does != mean in Python?
!= means "not equal to". It gives True when the two values are different and False when they are the same.
Why does Python say TypeError when I compare input with a number?
input() returns text, and Python will not compare text with a number using < or >. Wrap the input in int() or float() first.
Is 10 < x < 20 allowed in Python?
Yes. Python supports chained comparisons. It means x is greater than 10 and also less than 20.
How does Python compare two words with < or >?
It compares them letter by letter, like a dictionary. Capital letters come before small letters, so lower both words for a fair test.