True or False: Booleans

Yes or no

A boolean (bool) has only two possible values: True or False. Think of it as the answer to a yes/no question.

is_raining = False
has_ticket = True
print(is_raining)
print(has_ticket)

Output

False
True

Write them with a capital first letter and without quotes. true or "True" are not booleans.

Questions that give a boolean

When you compare things, Python answers with True or False:

print(10 > 3)
print(2 == 5)
age = 16
print(age >= 18)

Output

True
False
False

== asks “are these equal?”. You'll use booleans a lot in the module on making decisions.

Remember: = stores a value. == compares two values.

HOME LEARN COMMUNITY DASHBOARD