Boolean Values and Operators
Boolean Values and Operators
operators
Boolean values and expressions
• if (enteredPassword == "magic")
• {
• passwordIsValid = true;
• }
• else {
• passwordIsValid = false;
• }
Boolean expression
• A Boolean expression is an expression that
evaluates to produce a result which is a Boolean
value.
• For example, the operator == tests if two values
are equal.
• It produces (or yields) a Boolean value.
• So another much more compact way to write
lines previous slite code would be like this:
• passwordIsValid = enteredPassword == "magic";
Comparison operators
• When comparing strings, Python will check for alphabetical ordering. "a" comes
before "b", "can" comes before "candle", and remember upper case letters come
before lower case.
The and operator takes two values, v1 and v2, and implements the
following table to find the result.