I’m trying to combine multiple not conditions in a single line but I can’t make it. This is how the conditional statements should be built upon:
when stat has a value and both the value of alternative and successor are nothing then only the script should print true.
When I try the following, I get true as the result.
stat = "o"
alternative = ""
successor = ""
if stat and not (alternative and successor):
print("true")
However, When I execute the following, I also get true as the result
stat = "o"
alternative = "p"
successor = ""
if stat and not (alternative and successor):
print("true")
How can I rectify the condition above to serve the purpose?
Advertisement
Answer
both the value of
alternativeandsuccessorare nothing
This literally translates to
not alternative and not successor
By De Morgan’s laws it is equivalent to
not (alternative or successor)