In a comment on this question, I saw a statement that recommended using
result is not None
vs
result != None
What is the difference? And why might one be recommended over the other?
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.
==is an equality test. It checks whether the right hand side and the left hand side are equal objects (according to their__eq__or__cmp__methods.)isis an identity test. It checks whether the right hand side and the left hand side are the very same object. No methodcalls are done, objects can’t influence theisoperation.You use
is(andis not) for singletons, likeNone, where you don’t care about objects that might want to pretend to beNoneor where you want to protect against objects breaking when being compared againstNone.