I have a simple logic if statement returning an invalid syntax error. The statement is:
if (a[1] != None and a[2] != None and !(a[3] == None and a[4] == None)):
The invalid syntax is the third ! operator. Any reason why this would not work? Is there another operator I am supposed to use in this situation?
So the logic is essentially: a[1] ^ a[2] ^ (a[3] v a[4])
(where these denote having values). Hence the reverse logic for getting no None
values is:
!a[1] ^ !a[2] ^ !(a[3] ^ a[4])
I'm pretty sure my logic maths is right, so how do I get the result I require?
*Background info: Python 2.7.10, overall code is pulling data out of an SQL Server 2008 table, manipulating it and then inserting it into a different table that doesn't allow NULL values, and the original table is littered with NULLs
Thanks for your help!
The logical not operator in python is not !
but rather is not
.
You want:
if (a[1] != None and a[2] != None and not (a[3] == None and a[4] == None)):