โ๏ธ Boolean
5th Grade ๐ป Coding
A Boolean is a type of data that has only two possible values: true or false. In Python you write them as `True` and `False`, with a capital letter.
The name comes from George Boole, a 19th-century English mathematician who studied the math of true and false โ โand,โ โorโ and โnot.โ About a hundred years later, his ideas became a foundation of computing. Every comparison, like 7 > 5, gives back a Boolean value: True.
Boolean variables are especially useful for keeping track of a state: โIs the game over?โ, โIs the character jumping right now?โ, โIs the door open?โ In Scratch, Boolean blocks are shaped like pointy hexagons, and they fit exactly into the slot of a condition.
For example
- A game has a variable
game_over = False, and when the lives run out it switches toTrue. - The question โIs today Saturday?โ is Boolean โ the answer can only be yes or no.
- A light switch is like a Boolean value: on or off, with no third setting in between.
๐ Remember: Boolean = only two states: True or False, like a switch.
Quick quiz
How many values can a Boolean have?
Who is the Boolean named after?
What does 7 > 5 give back?