【问题标题】:Operator != vs <> [duplicate]运算符!= vs <> [重复]
【发布时间】:2015-09-23 05:54:40
【问题描述】:

学习python。我怀疑使用以下运算符:

!=  —> Checks if the value of two operands is equal or not, if values are not equal then condition becomes true.
<> —> Checks if the value of two operands is equal or not, if values are not equal then condition becomes true.

上面的定义对(referred from book)?如果是,当我们同时使用这两个运算符时。请在正确的情况下分享您的经验!!!

【问题讨论】:

    标签: python python-2.7 operators comparison-operators


    【解决方案1】:

    来自the documentation -

    &lt;&gt;!= 的形式是等价的;为了与 C 保持一致,!= 是首选;其中!= 在下面提到&lt;&gt; 也被接受。 &lt;&gt; 拼写已过时。

    (强调我的)

    它们是等价的,但你应该使用!=&lt;&gt; 运算符在 Python 3.x 中也不存在。

    【讨论】:

    • 但是在 Python 3 中我可以做到:from __future__ import barry_as_FLUFL.
    • :-) 不应该是__past__ 吗?
    【解决方案2】:

    来自Python standard library Docs

    注意事项:

    1. != 也可以写成 ,但这只是为了向后兼容而保留的过时用法。新代码应始终使用 !=。

    因此,在检查相等性时,您应该始终使用 != 运算符。

    【讨论】:

      猜你喜欢
      • 2013-10-16
      • 1970-01-01
      • 2011-11-14
      • 2012-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多