Skip to content
dreamcode
dreamcode
Map
Comparisons
Lesson 8 of 77
+15 XP on finish
PYTHON BASICSChapter 2 · Conditionals and logic

Comparing values

A comparison evaluates two values and returns a boolean value: either True or False. Use == to check if values are equal, != for not equal, and <, >, <=, >= for numeric ordering.

Worked example

How it reads

  • clouds < 5 checks if clouds is less than 5, giving True
  • clouds == 10 checks for equality, giving False
  • clouds != 0 checks if clouds is not equal to 0, giving True
Cloud tip: In Python, double equals == is used to compare two things, while a single equals = is used to store a value in a variable.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Add a second check that prints whether stars is between 100 and 200 using a chained comparison like 100 < stars < 200. The output should be True and then True.

Press Run to check your work.