Logical Operators
Learn about logical operators with examples.
We'll cover the following...
Logical operators can be used to combine two or more statements to produce a compound statement that returns a Boolean value.
Guess who?
“Guess who?” is a popular family game that involves trying to guess a person by asking “yes” or “no” questions about their appearance. We’re going to consider a smaller version of the game to demonstrate some logical operators.
Our smaller game only has four characters: Alfie, Betty, Gemma and Del.
Each character has two particular characteristics: they either wear a hat or they don’t, and they either wear glasses or they don’t.
For example, if we asked “Who is wearing glasses?”, the answer would be “Betty and Del”.
Negation (logical NOT)
Negation returns the opposite of a value’s Boolean value. So truthy values will ...