Imagine a light switch. It can be on or off. A boolean stores the same kind of two-choice information.
is_logged_in = TrueLine-by-line explanation
is_logged_innames a yes-or-no fact.=stores a value.Truemeans the answer is yes.
has_permission = FalseLine-by-line explanation
has_permissionnames another fact.Falsemeans 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
- The first line needs a boolean.
- The second line displays it.
Hint
- Choose
TrueorFalse. - Use a capital first letter.
- Do not use quotes.
Show Solution
is_learning = True
print(is_learning)Line-by-line explanation
- The first line stores
True. - The second line reads it.
- The output is
True.