Yes In your q.remove(y) example, the first occurrence of an object that is compared to y is deleted. However, as class A is defined, you should not β ever have a comparison value equal to y - with the exception of any other names that are also tied to the same y instance.
The relevant section of the documents is here :
If the operation __cmp__(), __eq__() or __ne__() not defined, the class instances are compared by the identifier of the object ("address").
Thus, the comparison for instances of A carried out by identifier (implemented as a memory address in CPython). No other object can have an identifier equal to id(y) during y lifetime, that is, as long as you keep the link to y (which you must remove if you are going to remove it from the list!)
β Technically, it is still possible to have objects in other memory cells that are compared with equals - mock.ANY is one such example. But these objects must redefine their comparison operators to force the result. Sub>
source share