How should functions be tested for equality or identity?

前端 未结 4 2046
眼角桃花
眼角桃花 2020-12-04 19:54

I would like to be able to test whether two callable objects are the same or not. I would prefer identity semantics (using the \"is\" operator), but I\'ve discovered that wh

4条回答
  •  感动是毒
    2020-12-04 20:55

    You can use foo is bar that is the same id(foo) == id(bar) to check identity. If you want to check 'equality' (value) use ==.

提交回复
热议问题