Strict comparison

后端 未结 5 1901
再見小時候
再見小時候 2021-01-17 11:43

In javascript, there are strict comparison operators op1 === op2 and op1 !== op2 that will compare both type and value. Is there a pythonic way of

5条回答
  •  深忆病人
    2021-01-17 12:17

    In python there is only one strict comparison operator that is == Suppose we have 2 cases:

    >>> 2 == '2'
    False
    
    # Comparison of Int with string, it returns False
    
    >>> 2 == 2.0
    True
    
    # Comparison of Int with Float, it returns True
    

    However in other programming languages like Julia, There is a distinction between comparison operator and strict comparison operator.

    >>> 2 == 2.0
    true
    
    >>> 2 === 2.0
    false
    
    # strict comparison operator, namely === which is true only if two values agree fully as to type as well as value.
    

提交回复
热议问题