How do I achieve the effect of the === operator in Python?

前端 未结 4 1336
轮回少年
轮回少年 2021-01-11 12:22

How do I achieve the effect of the === operator in Python?

For example, I don\'t want False == 0 to be True.

4条回答
  •  庸人自扰
    2021-01-11 12:50

    Going with the Mathematica definition, here's a small function to do the job. Season delta to taste:

    def SameQ(pram1, pram2, delta=0.0000001):
        if type(pram1) == type(pram2):
            if pram1 == pram2:
                return True
            try:
                if abs(pram1 - pram2) <= delta:
                    return True
            except Exception:
                pass
        return False
    

提交回复
热议问题