a == b is false, but id(a) == id(b) is true?

前端 未结 3 1000
眼角桃花
眼角桃花 2021-01-04 07:33

Ran into the following:

>>> class A:
...     def __str__(self):
...             return \"some A()\"
... 
>>> class B(A):
...     def __str_         


        
3条回答
  •  隐瞒了意图╮
    2021-01-04 08:17

    For those of us here attracted by your title, to determine whether a method was overridden:

    class A:
        def __str__(self):
            return "some A()"
    
        def strWasOverridden(self):
            return A.__str__ != self.__str__
    

提交回复
热议问题