Practicality of Booleans
A huge part of programming, in any language, have always been boolean statements. While we are not going to focus on the actual coding today, we are going to learn about what booleans are!
A Refresher: What are Booleans?
Boolean statements are expressions that result in a value that is either True or False. These two responses are the only outputs that come out of these statements, and are extremely important in programming and everyday life!
Booleans in Daily Life?
While you might not realize it, Boolean statements are used everyday! Here are some examples of how they are used:
- When your parents ask you if you finished your homework yet. Since your response is either yes or no, it is considered to be a boolean expression.
- A game of twenty questions is a series of different boolean expressions that are used in order to guess the character that the person is thinking of.
- When you have true or false questions on a test, since the output is a true or false response, those expressions are booleans.
- A to-do list is also considered to be boolean statements. The statements are tasks that should be done and the checks that are written down if the task is complete are the boolean outputs. If the task is completed, the check represents true. If the check box is blank, then the statement is false.
- On and Off switches in your house are boolean statements
Booleans in Computer Programming?
As stated earlier, boolean expressions are used often in programming languages. The software programming of a computer is actually made up of various boolean statements! While we are not going to go into the specifics of booleans in Python today, here are some of the ways that booleans are used in coding.
- Booleans are often used to compare numbers with each other. As an example, 1 < 3 evaluates to True, while 1 > 3 evaluates to False.
- Identity Operators are used to check if variables are equal to each other. If P = ‘hi’ and P = C, then C == “hi” will result in True (two equal signs simply checks if the left hand side is equal to the right hand side)