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("You got it!")
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
- A relational operator compares two values. The comparison, called a condition, comes out True or False.
- != is 'not equal to'. It asks one question: are these two values different?
- Different means True. Exactly the same means False.
Have a goA classmate swears 8 != 8 is True 'because it's got a not in it'. Can you talk them out of it? What does it really give?
False
Both values are 8, and != only gives True when the two values are different.
- == asks the opposite question: are the two values equal?
Have a goSay 4 == 9 comes out False. Without working anything else out, what does 4 != 9 come out as?
True
== and != ask opposite questions, so for any pair of values one is True and the other is False.
- A single = isn't a comparison at all. It's assignment, and it stores a value.
- There are six relational operators: ==, !=, <, <=, > and >=.
Have a goBesides !=, one other operator in the list gives True for 7 and 3 but False for 7 and 7. Which one?
>
7 > 3 is True, but 7 > 7 is False because a value is not bigger than itself.
- English into code: 'total is not equal to 100' becomes total != 100.
- In an if / elif / else, the first condition to come out True picks the branch that runs.
- Those are Python's symbols. Other languages may use different ones.
The big picture
Here's the whole idea in four sentences. A relational operator compares two values, and the comparison (a condition) always comes out True or False. Not equal to, written != in Python, asks 'are these two values different?': True when they differ, False when they're the same. It's the opposite of ==, which asks whether two values are equal, and neither is the same as a single =, which is assignment. Put it in an if / elif / else and the first condition to come out True picks the branch that runs.
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 27 October 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.