运算符 != 与 <>

Operator != vs <>

学习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)?如果是,当我们同时使用这两个运算符时。请分享您的经验和正确的情况!!!

来自the documentation -

The forms <> and != are equivalent; for consistency with C, != is preferred; where != is mentioned below <> is also accepted. The <> spelling is considered obsolescent.

(强调我的)

它们是等效的,但您应该使用 !=<> 运算符也不在 Python 3.x 中。

来自Python standard library Docs

Notes:

  1. != can also be written <>, but this is an obsolete usage kept for backwards compatibility only. New code should always use !=.

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