Comparison

From the syllabus

AQA: Be familiar with and be able to use ... (3.1.1.4/4.1.1.4)}

  • equal to, not equal to, less than, greater than, less than or equal to, greater than or equal to

Comparison operators are used to compare two or more values/variables returning either true or false (boolean values). They work as you would expect from Maths, in the table below we'll assume a = 4 and b = 5:

Operator Description Example
> greater than a > b -> False
< less than a < b -> True
>= greater than, or equal to a >= b -> False
<= less than, or equal to a <= b -> True
== equal to a == b -> False
!= not equal to a != b -> True

Be careful with == and do not confuse it with the assignment operator =.