Understood. Let’s walk back a little to where we only know about
if and nothing about
# condtion is truthy
if is like an operator that works on its argument. Given any object or expression it will behave the same. Evaluate this in terms of truthiness. Nothing that isn’t truthy will get past this point and will be shunted off to the next claus (elif, else) or the program statement following.
Logic is all about truth factors. There are only two,
False. That’s it. Every object can be boiled down to one of these two. Call them cases if you will; I do for variation in thinking about logic.
it is going to rain tonight
Is that truthy, or falsy? Other factors may come into play. Are there clouds on the horizon? Is it forty below zero outside (only thing reining (pun) is cold)?
The above may well prove out, but it is only an assertion until then.
it rained last night
Is that truthy or falsy? Assuming it did rain, we would take it as truthy.
if it rained last night:
the assertion was correct
But in cases where there is doubt, we always need another avenue of testing assertions.
Logical operators are a tool we use for this purpose (among others, perhaps).
if prediction of rain AND temperature suitable AND cloudy:
Logic is about judgement and determination as opposed to imperative.
AND is an operator that short-circuits if it encounters a falsy. The whole thing just shuts down and hands back,
That’s the end of the evaluation. This tells us that if we have condition that is likely to fail, then put it last and let the others have a chance first, to succeed if they may.
x = 
if len(x) and x
This will not raise an exception because the doable operation came first. The second operand will never be evaluated.
x = 
if x and len(x)
Will toss up an exception so quick your hands won’t have left the keys yet.
The operator is not blame here. The programmer is.
x = 
if not x and len(x)
What will that do?
if len(x) and not x
Bottom line, go down this rabbit hole and don’t come back up until you are dreaming about logical operators in your sleep, literally.
Arm yourself with simple truth tables for each of AND, OR, NOT.
Bear in mind that AND and OR are operators whereas NOT is a modifier. Operators are binary, modifiers are unary. They prefix and sometimes suffix a singular adjacent object.
First off, whatever a evaluates as, truthy or falsy will become a boolean. The next thing to happen will be toggling that boolean. Given we have only two factors, that is simple enough. True becomes False; False becomes True. Hardly any evaluation process here. It is imperative. But the evaluation of
a was determinative. We had to squeeze it to see what came out.