Difference between == and === in Mathematica

后端 未结 5 1145
太阳男子
太阳男子 2020-12-31 11:10

I was under the impression that = is an assignment, == is a numeric comparison, and === is a symbolic comparison (as well as in some o

5条回答
  •  一整个雨季
    2020-12-31 12:10

    One important difference is that === always returns True or False. == can return unevaluated (which is why it's useful for representing equations.)

    In[7]:= y == x^2 + 1
    
    Out[7]= y == 1 + x^2
    
    In[8]:= y === x^2 + 1
    
    Out[8]= False
    

    There are some interesting cases where == returns unevaluated that are worth being aware of while programming. For example:

    In[10]:= {} == 1
    
    Out[10]= {} == 1 
    

    which can affect things like If[foo=={}, , ].

提交回复
热议问题