All of these are "yes or no" questions, and we may want to take different actions depending ono the answer to the question. For example, if the answer to the second question is "yes," we want to tell the customer they canβt take out that much money; if the answer is "no," we go ahead and let them have their money.
We ask a yes/no question in Python by writing a boolean expression (named after George Boole, a 19th century mathematician). A boolean expression asks a question whose answer is either true (yes) or false (no). is an expression that is either true or false. The following examples use the operator ==, which compares two operands and produces True if they are equal and False otherwise:
x != y # x is not equal to y
x > y # x is greater than y
x < y # x is less than y
x >= y # x is greater than or equal to y
x <= y # x is less than or equal to y
Although these operations are probably familiar to you, the Python symbols are different from the mathematical symbols for the same operations. A common error is to use a single equal sign (=) instead of a double equal sign (==). Remember that = is an assignment operator and == is a comparison operator. There is no such thing as =< or =>.
The comparison between two numbers via == results in either True or False (in this case False), both Boolean values.
3 + 4
3 + 4 evaluates to 7, which is a number, not a Boolean value.
3 + 4 == 7
3 + 4 evaluates to 7. 7 == 7 then evaluates to True, which is a Boolean value.
"False"
With the double quotes surrounding it, False is interpreted as a string, not a Boolean value. If the quotes had not been included, False alone would in fact be a Boolean value.
x is y # x is the same object as y
x is not y # x is not the same object as y
While these might seem to be just another way of saying x == y and x != y, they are different in a very important way. Explaining that difference would take us into a fairly advanced topic, so weβll leave is and is not for later in the course. For now, use == to ask if two values are equal, and use != to ask if they are not equal.