Explore

Learn: Comparison Operators
OCR GCSE J277 Computer Science specification
Ready to start this lesson?
Sign in to track your progress. 12 steps including 6 interactive questions.
Sign In to Start LearningStudents also studied
Browse allSteps in this lesson (12)
Welcome!Welcome back! In this lesson, we will build on your knowledge of variables, selection, and iteration to explore comparison operators. These operators help us compare values and make decisions in our programs.By the end of this lesson, you'll understand how to use operators like ==, !=, , , >, and >= to control the flow of your code.
What Are Comparison Operators?Comparison operators are used to compare two values. They return a Boolean result: either true or false. This is essential for decision-making in programming.For example, you can check if two numbers are equal, if one is greater than the other, or if they are not equal.
Key Comparison OperatorsHere are the comparison operators we’ll focus on:==: Checks if two values are equal.!=: Checks if two values are not equal.: Checks if the first value is less than the second.: Checks if the first value is less than or equal to the second.>: Checks if the first value is greater than the second.>=: Checks if the first value is greater than or equal to the second.
Quick check: Which operator checks if two values are equal?
Start the lesson to answer this multiple choice question
How Do Comparison Operators Work?Comparison operators compare two values and return true or false. For example:5 == 5 returns true because the numbers are equal.10 != 5 returns true because the numbers are not equal.7 returns false because 7 is not less than 3.
The operator {{blank0}} is used to check if two values are not equal.
Start the lesson to answer this fill in the blank question
Using Comparison Operators in ProgramsComparison operators are often used in conditional statements like if and while to control program flow. For example:if age >= 18: print('You are an adult')The program checks if age is greater than or equal to 18. If true, it prints a message.
Match the items on the left with their correct pairs on the right
Start the lesson to answer this matching question
Review Time!Well done! You've learned about the different comparison operators and how they work. Let's test your understanding with a few more questions.
Which of the following statements are true? (Select all that apply)
Start the lesson to answer this multi-select question
Match the items on the left with their correct pairs on the right
Start the lesson to answer this math equation question
Match the items on the left with their correct pairs on the right
Start the lesson to answer this code completion question

Want to Learn More?
Get personalised lessons, quizzes, and instant feedback from your AI tutor.
Explore More Topics