Python ( or general programming ). Why use <> instead of != and are there risks?

牧云@^-^@ 提交于 2020-01-09 05:36:25

问题


I think if I understand correctly, a <> b is the exact same thing functionally as a != b, and in Python not a == b, but is there reason to use <> over the other versions? I know a common mistake for Python newcomers is to think that not a is b is the same as a != b or not a == b.

  1. Do similar misconceptions occur with <>, or is it exactly the same functionally?
  2. Does it cost more in memory, processor, etc.

回答1:


<> in Python 2 is an exact synonym for != -- no reason to use it, no disadvantages either except the gratuitous heterogeneity (a style issue). It's been long discouraged, and has now been removed in Python 3.




回答2:


Just a pedantic note: the <> operator is in some sense misnamed (misdenoted?). a <> b might naturally be interpreted as meaning a < b or a > b (evaluating a and b only once, of course), but since not all orderings are total orderings, this doesn't match the actual semantics. For example, 2.0 != float('nan') is true, but 2.0 < float('nan') or 2.0 > float('nan') is false.

The != operator isn't subject to such possible misinterpretation.

For an interesting take (with poetry!) on the decision to drop <> for Python 3.x, see Requiem for an operator.




回答3:


you shouldn't use <> in python.



来源:https://stackoverflow.com/questions/2312169/python-or-general-programming-why-use-instead-of-and-are-there-risks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!