You may have learnt how to use the or and and operators when working with boolean values, but there is one detail you might be missing, and that is: how they actually work. The python docs say (Emphasis mine):
Note that neither and nor or restrict the value and type they return
to False and True, but rather return the last evaluated argument. This
is sometimes useful, e.g., if s is a string that should be replaced by
a default value if it is empty, the expression s or 'foo' yields the
desired value....)
As you can see, the or and and operators are not restricted to returning True or False, and I will add they are not restricted to working explicitly with boolean expressions, instead they act like expression evaluators, and return the last expression which is Truthy.
Two lessons about the or operator
Or evaluates expressions
or will either return the value of the expression on the right side if it is truthy, otherwise the expression on the left side is evaluated, and that becomes the result of the entire statement.
Or is lazy
Implicit in the first lesson, is the notion of lazy evaluation. It is important to understand that evaluation of the expression is not done immediately, this is another way of saying the evaluation is lazy. Consider the following:
v = True or <some expensive database fetch which might take long time>
In the above, <some expensive database fetch which might take long time> will never be evaluated because the left expression was truthy (actually true in this case), therefore the value of v will be True.
This concept is further solidified if you understand why the following will not raise a ZeroDivisionError exception:
n = 45 or (1/0)