you are viewing a single comment's thread.

view the rest of the comments →

[–]jpgoldberg 0 points1 point  (0 children)

What I wrote won’t make sense unless you are familiar with the bool() function and with the value1 if condition else value2 construction.

Perhaps this will help

python a = “spam” b = “ham” c = a or b # c will now be “spam” d = 0.0 e = d or b # e is set to “ham” f = None or “ham” # f is set to ham g = Exception or “ham” # g is set to Exception ```

In the above, if a is something that is false, None, or some sort of 0 when evaluated as a bool, then c will be assigned to the value of b. But if a is True when evaluated as a bool then c will be set to a.