GCSE · Computer Science · AQA · Spec 8525
Not equal to (relational operator)
Picture a lock screen asking one question about your PIN: is it different from the real one? Yes, it stays locked. No, you're in. That question is !=.
Computer Science · Programming
One question, three different paths
The secret number is 10. Step through three runs of the same code and watch what guess != 10 answers each time.
Before you step through run 2: when the player types 10, which message do you think gets printed?
1 guess = int(input("Your guess: "))2 if guess > 10:3 print("Too high")4 elif guess != 10:5 print("Too low")6 else:7 print("Spot on!")
Variables
Output
Your guess: 7
Step 1: Run 1. The player types 7, so guess now holds 7.
Press Next to move one line at a time. Watch which line lights up after each question is answered.
Your turn
True or False?
Pick a comparison, then drop it into the answer it evaluates to.
Still to sort
Evaluates to True (0)
The two values are different.
Where the line is: Any difference at all counts. Being close (49 and 50) is still different.
Evaluates to False (0)
The two values are exactly the same.
Where the line is: Work out each side first. If both sides come to the same value, != gives False.
No program this time, just the comparisons. Commit to an answer for each one, then read why.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
A question your program asks: are these two values different? The answer is always True or False, and that answer picks the path.
What you need to know
- Say what a relational operator does and what a condition evaluates to.
- Read != as 'not equal to' and evaluate a != comparison to True or False.
- Tell != apart from == (equal to) and from a single = (assignment).
- Name the six relational operators: ==, !=, <, <=, > and >=.
- Write a != condition from an English statement, such as 'total is not equal to 100'.
- Follow which branch of an if / elif / else runs when a condition uses !=.
The big picture
A relational operator compares two values, and the comparison (a condition) evaluates to either True or False. Not equal to, written != in Python, asks whether two values are different: it gives True when they differ and False when they're the same. It's the opposite of ==, which asks whether two values are equal, and neither should be confused with a single =, which is assignment. As the condition of an if / elif / else, a != comparison helps decide which branch runs: the first condition to evaluate to True wins.
Key points
Worked example
Problem
A vending machine stores the amount paid, in pence, in a variable called paid. Write an if / else that prints "Please pay 150p" when paid is not equal to 150 and "Thank you" otherwise. Then say what it prints when paid is 150, and when paid is 200.
⚠ Watch out
Writing a single = in a condition, as in if total = 100:. A single = is assignment: it stores a value rather than comparing. To ask 'the same?' use ==, and to ask 'different?' use !=.
Memory hook
Read the ! as 'not': != is 'not equal'. Then ask it out loud: 'Different?' Yes means True. No means False.
Check yourself
x holds 6. What do x != 6 and x != 9 evaluate to? (x != 6 is False: the values match. x != 9 is True: 6 and 9 are different.)
Flashcards
(13)What does a relational operator do?
What does != mean?
How is 'not equal to' written in Python?
When does a != comparison evaluate to True?
What does a != comparison give when both values are the same?
What does == check?
What does a single = do in Python?
How are == and != related?
Name the six relational operators.
Write 'total is not equal to 100' as code.
In an if / elif / else, which branch runs?
Does a comparison like score != 0 change score?
Does every programming language write 'not equal to' as != ?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.