On 01.09.2021 10:27, Chris Angelico wrote:
> On Wed, Sep 1, 2021 at 5:19 PM Steven D'Aprano <st...@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.

I'm a bit puzzled by all this discussion around "is None".

None is a singleton, so there can only be one such object in any
Python process. Because there is only one, asking:

if x is None: ...

feels intuitive to me.

if x == None: ...

would also work, but misses the point about None being a singleton.

BTW: In SQL you have to use "field IS NULL", "field = NULL" returns
NULL, so you're not any smarter than before :-)

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Sep 01 2021)
>>> Python Projects, Coaching and Support ...    https://www.egenix.com/
>>> Python Product Development ...        https://consulting.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               https://www.egenix.com/company/contact/
                     https://www.malemburg.com/

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/46NOM3Y3RMTVEDIZIBHBFHOX2XVH764Q/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to