So basically I am trying to retrieve values from a database. My if case is that if the query result which is saved in variable data is None then it should print message data not found. If the value is not none then it should print the data. My problem is that I am on purpose giving it a value which is not present in the database which means data should be null. But my if none case is not triggering. It goes directly to else. I have attached pictures down below. Apologies if this question is too basic.

-
If you have code, why would you post it as an image? Could you please post your code as formatted text (Ctrl+K)?JE_Muc– JE_Muc2020-03-03 17:58:40 +00:00Commented Mar 3, 2020 at 17:58
-
1@Scotty1- I apologize. Will make sure to do that next time.Zaid Alvi– Zaid Alvi2020-03-03 18:05:56 +00:00Commented Mar 3, 2020 at 18:05
Add a comment
|
1 Answer
This is because you are testing if the data variable is am instance of the None object which, from your output, it's not it's a list.
So all you need to do is to change your if statement to if not data: which will fix the problem.
Not will pass true for None, False and empty list amongst other things. see Python Truth Value Testing
1 Comment
Steve Mapes
Excellent, would you mind up-voting (Clicking on the up arrow) and selecting my post as the selected answer for your question please to help anyone in the future who has the same problem.
![data variable with value []](https://www.lemona.fr/i.sstatic.net/XMPms.png)