[Python-Dev] == on object tests identity in 3.x (original) (raw)

Chris Angelico rosuav at gmail.com
Mon Jul 7 17:22:54 CEST 2014


On Tue, Jul 8, 2014 at 1:15 AM, Benjamin Peterson <benjamin at python.org> wrote:

Why do you think that?

% python Python 2.7.6 (default, May 29 2014, 22:22:15) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.

class x(object): pass ... class y(object): pass ... x != y True x == y False

Your analysis is flawed - you're testing the equality of the types, not of instances. But your conclusion's correct; testing instances does work the same way you're implying:

rosuav at sikorsky:~$ python Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information.

class x(object): pass ... class y(object): pass ... x() != y() True x() == y() False x() == x() False z = x() z == z True

ChrisA



More information about the Python-Dev mailing list