Summary

We've looked closely at Python's Boolean data type, which only has two values (True and False) and four operators: and, or, not, and if-else. The Boolean operators and the if statement will both implicitly coerce values to a Boolean. This means that non-empty strings will behave in the same as the True value.

We've looked at the comparison operators. These work with other objects and create Boolean results.

In the case of numeric comparisons, the numeric coercion rules are used to allow us to compare float against int values without having to write explicit conversions. For string or tuple values, we've seen that items are compared in order.

We've also seen how the logical operators of or and and are not strict about evaluating their operands. ...

Get Python Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.