1

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. enter image description here

data variable with value []

2
  • If you have code, why would you post it as an image? Could you please post your code as formatted text (Ctrl+K)? Commented Mar 3, 2020 at 17:58
  • 1
    @Scotty1- I apologize. Will make sure to do that next time. Commented Mar 3, 2020 at 18:05

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.