On Thu, Sep 2, 2021 at 5:56 PM Stephen J. Turnbull
<stephenjturnb...@gmail.com> wrote:
>
> Steven D'Aprano writes:
>  > On Thu, Sep 02, 2021 at 04:04:40PM +0900, Stephen J. Turnbull wrote:
>  >
>  > > You may not need to teach them about singletons, though.
>  >
>  > It's hard to teach why `is` works with None,
>
> For definitions of "works" that comes down to "agrees with Nick that
> 'is' is just a weird way to spell '==' most of the time".  But that's
> not how I think of 'is'.
>
>  > but not with 1.234 or [], without talking about the object model
>  > and singletons.
>
> Object model, of course, but singletons?  AFAICS, "singleton" is a red
> herring here.  Object model is important for '[]': there are times
> where it's important that 'a == b == [] and a is b', and other times
> where it's important that 'a == b == [] and a is not b'.  But from the
> point of view of beginner education, at least, there's no reason why
> None and Ellipsis couldn't share a SpecialObjects type (although you
> couldn't put False and True in there).
>
>  > To say nothing of why it works with 0 and 1 but not 123456.
>
> Case in point for singletons being a red herring.  True == 1 but
> True is not 1 (in Python 3.10).  Neither object is a singleton.

I would say "special value" rather than "singleton". True and False
are a.... doubleton? You're not able to construct additional instances
of that type, which is the main defining trait of the singleton. There
just happen to be two of them.

(Not that I *often* use "is False" or "is True", but it has been
known, and certainly it's more correct than "== True".)

ChrisA
_______________________________________________
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/6ZRXD5QBR64JQ3S6TUHG34XL3IBFJPXP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to