On Tue, Aug 31, 2021 at 7:22 AM Chris Angelico <ros...@gmail.com> wrote: > > On Tue, Aug 31, 2021 at 7:17 AM Nick Parlante <n...@cs.stanford.edu> wrote: > >> > >> On what basis do you ascertain whether "==" would work correctly? > >> Please explain. > > > > > > Hi Chris, I'm just glancing at the line of code, and doing a little thought > > experiment to see if it would get the same output if == was used instead. > > For a singleton like None or False or the class like "list" .. == will > > return the same answer as "is". Look at these lines; > > > > if type(items) is list: > >
Oh, and this one is a little more work to prove, but it can be done. >>> class Meta(type): ... def __eq__(self, other): return True ... >>> class List(list, metaclass=Meta): pass ... >>> items = List([1, 2, 3]) >>> items [1, 2, 3] >>> type(items) is list False >>> type(items) == list True (If you prefer, you could have items be a dict-like type instead of list-like, so it compares equal to list but doesn't behave like one. The demonstration is identical.) 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/76P4HIEYW5UGYV5M3SFCQTGVD2TIBFYX/ Code of Conduct: http://python.org/psf/codeofconduct/