
On Wed, Sep 1, 2021 at 5:19 PM Steven D'Aprano <steve@pearwood.info> wrote:
Outside of contrived counter-examples, we're not likely to come across anything trying to mimac None in the real world. But that's not really why we use `is`, or at least, it's not the only reason. There are a bunch of reasons, none of which on their own are definitive, but together settle the issue (in my opinion).
1. Avoid rare bugs caused by weird objects. 2. Slightly faster and more efficient. 3. Expresses the programmer's intent. 4. Common idiom, so the reader doesn't have to think about it.
And in terms of education, these sorts of reasons are the things I tend to wrap up behind the description "best practice". For instance, why do we write file management using the 'with' statement? You could argue that it's because other Python implementations may behave differently, or future versions may behave differently, or there's the risk that the file wouldn't be closed because of some other reference... but the easiest explanation is "that's the standard idiom", and then you can explain the reasons as the justifications for it being standard. ChrisA