Contact
Evil Genius SocietyHomeLearnForumLeaderboardSocialsMessages
← Back to module

Lesson 1 of 10

A boolean is a value that is either True or False. Those are the only two booleans in Python, and both are capitalised.

is_raining = True
is_sunny = False
print(is_raining)
print(type(is_raining))

Booleans matter because they are how a program answers yes-or-no questions — and in the next few lessons, how it decides what to do next.

Comparison operators

You rarely type True by hand. Usually you compute a boolean by comparing two values:

| Operator | Meaning | | --- | --- | | == | equal to | | != | not equal to | | > | greater than | | < | less than | | >= | greater than or equal to | | <= | less than or equal to |

age = 20
print(age >= 18)
print(age == 21)
print(age != 21)

= versus ==

This trips up almost everyone at first:

  • = assigns. age = 20 puts 20 into age.
  • == compares. age == 20 asks "is age equal to 20?" and gives back True or False.
score = 10
print(score == 10)
print(score == 99)

Comparing strings

Comparison works on strings too. == checks that the text matches exactly — including capitalisation.

print("cat" == "cat")
print("Cat" == "cat")

Try it yourself

Set temperature to 32, then print whether it is above 30, whether it equals 32, and whether it is not equal to 32.

Checkpoint

  • Booleans are True or False — capitalised, no quotes.
  • Comparison operators (==, !=, >, <, >=, <=) produce booleans.
  • = assigns a value; == compares two values.

Questions about this lesson

Log in to ask a question.