==和===数学中的差异 [英] Difference between == and === in Mathematica

查看:131
本文介绍了==和===数学中的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的印象是 = 是一个赋值, == 是一个数字比较, c $ c> === 是符号比较(以及一些其他语言 == 等于 === 相同。这不一定是这种情况...

I was under the impression that = is an assignment, == is a numeric comparison, and === is a symbolic comparison (as well as in some other languages == being equal to and === being identical to. However, looking at the following it would appear that this is not necessarily the case...

In: x == x
Out: True

In: x === x
Out: True

In: 5 == 5
Out: True

In: 5 === 5
Out: True

In: x = 5
Out: 5

In: 5 == x
Out: True

In: 5 === x
Out: True

In: 5 5 == 5x
Out: True

In: 5 5 === 5x
Out: True

In: x == y
Out: x == y

In: x === y
Out: False

In: y = x
Out: 5

In: x == y
Out: True

In: x === y
Out: True

那么,在Mathematica中==和===的区别是什么?我一直在看文档,但我还是不太明白。

So what exactly is the difference between == and === in Mathematica? I have been looking at the documentation but I still don't quite understand it.

推荐答案

一个重要的区别是 === 始终返回 True False == 可以返回未评估(这是为什么它对于表示方程有用。)

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


$ b b

有一些有趣的情况, == 返回未评估,值得在编程时注意。例如:

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

In[10]:= {} == 1

Out[10]= {} == 1 

可以影响 If [foo = = {},< true>,< false>]

这篇关于==和===数学中的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆