Skip to content
BENIBIX Learn

Boolean

Development🧩 Programming ConceptsData and Variables

Also known as bool, True or False

A value that is only ever true or false. It works like a yes or no.

Think of it like

Think of it like a light switch. It is either on or off, and never in between.

Example

A music app keeps is_playing as a boolean. Press play and it becomes true; press pause and it becomes false.

Why it matters

Every choice a program makes comes down to a boolean. They are what an if checks.

Definition

A boolean is a value that can only be true or false. Programs use booleans to answer yes or no questions, like is the user logged in. A comparison, like 5 > 3, gives back a boolean. Ifs and loops use booleans to decide what to do next. The name comes from George Boole, who wrote the maths of true and false.

Example code

python
>>> 5 > 3
True
>>> 5 == 3
False
Each question gives back one of only two answers.

Common mistake

Storing yes and no as the strings "yes" and "no". Then a typo like "Yes" breaks the check.

Key takeaways

  1. 1
    Two values only. True or false, nothing else.
  2. 2
    From comparisons. Questions like a > b give a boolean.
  3. 3
    Drive decisions. Ifs and loops read them to choose.

Learn it properly