Python · Stage 2 – Doing Things with Values · Lesson 15 of 50

Comparison Operators

Compare two values and receive a True or False answer.

answer = 5 == 5
Line-by-line explanation
  1. The first 5 is compared with the second.
  2. == asks “are these equal?”
  3. The answer True is stored in answer.

!= means not equal. < and > mean less than and greater than. Adding = gives “less than or equal” and “greater than or equal”.

old_enough = 14 >= 13
Line-by-line explanation
  1. 14 is the value being checked.
  2. >= means greater than or equal to.
  3. 13 is the boundary.
  4. The result is True.