-4

I have a very simple beginner's question. I'm using python to re-write a php script on the server and I don't know how to translate this php code to python:

if(a && b && c && (!d || !e) doThis()

For python I only know how to do it the other way around

if a and b and c and (d or e):
    doThis(etc)

How can I check **NOT** d or **NOT** e?

hassan
  • 7,812
  • 2
  • 25
  • 36
Ditto
  • 296
  • 1
  • 13
  • `if not a and not b and not c: doThis()`? – Taku Mar 02 '17 at 07:40
  • 2
    I can't help but feel this is something that could have been easily googled. – apokryfos Mar 02 '17 at 07:43
  • `&` and `|` are **binary and operators**, not boolean operators. Use `and` and `or`. – Martijn Pieters Mar 02 '17 at 07:43
  • I'm guessing that the missing `)` in the if-statement is just a typo here on SO? Otherwise, it's quite easy write broken code in Python as well ;-) – M. Eriksson Mar 02 '17 at 07:44
  • @apokryfos I googled it and I couldn't find the answer plus it's midnight here. No need to be rude. Some people are working really hard 24/7. – Ditto Mar 02 '17 at 07:45
  • You can use `not`. Like: if a and b and c and (not d or not e): doThis(etc) Saying `not [variable name]` returns True if the variable doesn't exist. For example: if not a: print("test") Will print `test`. – Pike D. Mar 02 '17 at 07:45
  • @Ditto you can't assume that others of us are not working hard. – apokryfos Mar 02 '17 at 07:47
  • No need for a search engine, just look at the documentation: [Boolean operations](https://docs.python.org/3/reference/expressions.html#boolean-operations). – Matthias Mar 02 '17 at 07:48
  • @apokryfos Sorry, buddy. Not time for this. I'm trying to finish this thing. Have a good one. – Ditto Mar 02 '17 at 07:50

1 Answers1

1

there are many ways, and there are many other post out there that you just needed to do a simple google search to find.

if not a and not b and not c: 
    doThis()
Taku
  • 31,927
  • 11
  • 74
  • 85