I made a programming error in an algorithm which I didn't notice for a period of time. Doesn't matter the results were good and we wanted to implement this production in the productive system (model in python, productive system in c++).
So the first if statement in this algorithm should end the calculation if c == 0 or b == False
Unfortunately the statement was programmed like this:
if c == 0 is not b:
return
Instead of:
if c == 0 or not b:
return
My question now is, why is the first if statement no syntax error? I don't see any logical statement this should evaluate? Can someone explain as what the python interpreter interpretes this statement?
To understand the behaviour I calculated the truth table:
c | b | result
-------------------
0 | False | True
0 | True | True
1 | False | False
1 | True | False
So it seems that python tests for c == 0 and ignores the is not b, what ever this is meant to be. In my eyes it checks if the temporarily True or False statement is not the same object as b, what it never is, therefore we get the above resulting truth table. Is this thought correct?