x = None
if not x:
do_something()
^ Since x is None, will it enter the if statement?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Python has no value called
null, so your question doesn’t make sense.x == nullwill raise a NameError.Answer to your updated question: Yes, it will enter the if statement.
Noneis false in a boolean context, sonot Noneis true. You can see this yourself in the interactive interpreter:If you’re coming from a Java background, you should realize that Python makes it much easier to try things out. Get used to trying things in the Python interpreter. A lot of questions can easily be answered just by trying things yourself and seeing what happens.