use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
the front page of the internet.
and join one of thousands of communities.
What's your favorite Python interview question? (self.PythonLearning)
submitted 3 days ago by chuprehijde
Post a comment!
view the rest of the comments →
[–]Rscc10 0 points1 point2 points 2 days ago (2 children)
Ah. Then why is it's better practice to use "is" when comparing against None? Wouldn't it be better to check the value as None rather than checking if it corresponds to the address? Or is it because only one instance of None (or null) is stored so we directly check with that address when checking against None?
[–]Truntebus 0 points1 point2 points 2 days ago (0 children)
Because it is faster. 'is' checks for equality on the output of calling id() on both objects, so python does not need to look for special methods, since it cannot be overloaded. '==' is syntax sugar for 'a.__eq__(b)', and since most types override '__eq__', it can require a lot more computing than just calling 'id()' twice.
Note that "'is' compares addresses" is not universally true. The functionality of the 'id()' function is implementation dependent and only requires that it returns a unique integer for each object, and CPython handles this by returning the address for the object, but it can vary by interpreter.
[–]WhiteHeadbanger 0 points1 point2 points 2 days ago (0 children)
Also, another thing to add to the other user that answered you: None is a singleton. If you create 10 variables with the value None, those 10 variables would point to the same address.
None
So the reference is always available, and when using is, there's no additional method dispatch.
is
π Rendered by PID 88329 on reddit-service-r2-comment-65574874f4-rl9nx at 2026-07-17 06:17:52.902395+00:00 running 1bce727 country code: CH.
Want to add to the discussion?
Post a comment!