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

guess=7

Output

Your guess: 7

Step 1: Run 1. The player types 7, so guess now holds 7.

1 / 12

Press Next to move one line at a time. Watch which line lights up after each question is answered.

Step 1 of 12: Run 1. The player types 7, so guess now holds 7..

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.

6 of 6 still to sort.

No program this time, just the comparisons. Commit to an answer for each one, then read why.

The whole family

Six relational operators

Imagine comparing a first value with a second one, like a != b. For each operator, tick every situation where it gives True.

==
!=
<
<=
>
>=

One symbol, three jobs

=, == or !=?

A game runs the line lives = 3. Later it checks two conditions: lives == 3 and lives != 0.

Which of these is closest to what you think is going on?
How sure are you?

Spot the bug

Why is there no warning?

This program should print a warning whenever total is not equal to 100. A student sets total to 80 to test it, and the warning doesn't appear. Which line is wrong?

A student's program — which line goes wrong?

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

1A relational operator compares two values. The comparison, called a condition, always evaluates to True or False.
2!= means 'not equal to'. It asks 'are these two values different?', so total != 1 reads 'does total not equal 1?'.
3!= gives True when the two values are different and False when they're the same.
4!= is the opposite of ==, which asks whether two values are equal. A single = isn't a comparison at all: it's assignment. Other languages may use different symbols for these operators.
5The six relational operators are ==, !=, <, <=, > and >=.
6In an if / elif / else, the branch whose condition is the first to evaluate to True is the one that runs.

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?
It compares two values. The comparison (a condition) evaluates to True or False.
What does != mean?
Not equal to. It asks: are these two values different?
How is 'not equal to' written in Python?
An exclamation mark followed by an equals sign: !=
When does a != comparison evaluate to True?
When the two values are different.
What does a != comparison give when both values are the same?
False. They aren't different, so the answer to 'not equal?' is no.
What does == check?
Whether one value is equal to another. It's the equal to comparison.
What does a single = do in Python?
Assignment: it stores a value in a variable. It doesn't compare anything.
How are == and != related?
They're opposites. Compare any two values and exactly one of them is True.
Name the six relational operators.
== (equal to), != (not equal to), < (less than), <= (less than or equal to), > (greater than), >= (greater than or equal to).
Write 'total is not equal to 100' as code.
total != 100
In an if / elif / else, which branch runs?
The one whose condition is the first to evaluate to True. If none is True, the else branch runs.
Does a comparison like score != 0 change score?
No. It only reads the value and gives True or False. Only assignment changes a variable.
Does every programming language write 'not equal to' as != ?
Not necessarily. Other languages may use different symbols for their relational operators.

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 posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

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.