Computer Science
Grade 5
20 min
Comparison Operators
Comparison Operators
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Identify the six main comparison operators in Python.
Explain that comparison operators produce a Boolean value (True or False).
Write Python expressions using comparison operators with numbers.
Use the equality and inequality operators with strings.
Predict the Boolean outcome of a given comparison expression.
Use comparison operators inside a simple `if` statement.
Have you ever played a video game where you need a certain number of coins to buy an item? 🤔 The computer has to compare the coins you have with the price!
In this lesson, we will learn about special symbols called Comparison Operators. These operators let us ask the computer 'yes' or 'no' questions by comparing two things. This is a super important first step for making...
2
Key Concepts & Vocabulary
TermDefinitionExample
Comparison OperatorA symbol that compares two values and gives back a True or False answer.In `10 > 5`, the greater than symbol `>` is the comparison operator.
Boolean ValueA data type that can only have one of two values: `True` or `False`. It's like a light switch that is either on or off.The result of the comparison `5 == 5` is the Boolean value `True`.
ExpressionA piece of code that produces a value. A comparison is a type of expression.`my_score >= 100` is an expression that will result in `True` or `False`.
OperandThe values on either side of an operator that are being compared.In the expression `apples < oranges`, the operands are the variables `apples` and `oranges`.
Equality Operator (==)The operator used to check if two values are exactly t...
3
Core Syntax & Patterns
The Six Comparison Operators
== (Equal to), != (Not equal to), > (Greater than), < (Less than), >= (Greater than or equal to), <= (Less than or equal to)
These are the only six symbols used for comparing values in Python. You must use the correct symbol for the question you want to ask the computer.
The Boolean Result
Any expression with a comparison operator will always evaluate to either `True` or `False`.
The computer doesn't answer with numbers or strings. It only gives a `True` or `False` answer, which is perfect for making decisions in `if` statements.
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
What happens in this code? `level = 10; while level > 10: level = level - 1; print("Looping...")`
A.It prints 'Looping...' 10 times.
B.It prints 'Looping...' once.
C.It runs forever.
D.Nothing is printed.
Challenging
Consider this code: `is_raining = True; is_sunny = False; print(is_raining > is_sunny)` What will be printed?
A.True
B.False
C.Error
D.Nothing
Challenging
A game loop should stop when `lives` is less than or equal to 0. Which `while` loop is written correctly?
A.while lives < 0:
B.while lives <= 0:
C.while lives > 0:
D.while lives != 0:
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free