Python · Stage 1 · Storing Information · Lesson 11 of 50

True and False

Represent yes-or-no information with Python’s boolean values.

Imagine a light switch. It can be on or off. A boolean stores the same kind of two-choice information.

is_logged_in = True
Line-by-line explanation
  1. is_logged_in names a yes-or-no fact.
  2. = stores a value.
  3. True means the answer is yes.
has_permission = False
Line-by-line explanation
  1. has_permission names another fact.
  2. False means the answer is no.

True and False begin with capital letters and have no quotes. "True" would be text instead.

Tiny Practice: Store a Fact

Say whether you are learning Python, then display the value.

Starter template

is_learning = CHANGE_ME
print(is_learning)
Line-by-line explanation
  1. The first line needs a boolean.
  2. The second line displays it.
Hint
  1. Choose True or False.
  2. Use a capital first letter.
  3. Do not use quotes.
Show Solution
is_learning = True
print(is_learning)
Line-by-line explanation
  1. The first line stores True.
  2. The second line reads it.
  3. The output is True.