Does a Python object which doesn't override comparison operators equals itself?

后端 未结 3 458
独厮守ぢ
独厮守ぢ 2020-12-30 06:21
class A(object):

    def __init__(self, value):
        self.value = value

x = A(1)
y = A(2)

q = [x, y]
q.remove(y)

I want to remove from the li

3条回答
  •  醉梦人生
    2020-12-30 07:03

    In python, by default an object is always equal to itself (the only exception I can think of is float("nan"). An object of a user-defined class will not be equal to any other object unless you define a comparison function.

    See also http://docs.python.org/reference/expressions.html#notin

提交回复
热议问题