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

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?

Bug hunt

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

  • 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

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 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.