Dark theme

Key ideas in depth: assignments of condition results


In general, most people, at worse, assign the results of conditions thus:

a = variable < 10
if (a == True): # NB: is the same as "if(a):"

This is fortunately rarely needed, and it is better to keep conditions inside if statements where they won't be misunderstood. However, you can do more complicated assignments:

a = a or b
a = a and b

This resolves in the following complicated fashion:

With strings, the behaviour varies quite a lot depending on whether other strings are being printed.

In general, then, avoid assigning using Boolean operators; the response is likely to be non-obvious and difficult to debug.

a true, b true a true, b false a false, b true a false, b false
or b a b both zero
and b b a both zero