简体   繁体   English

什么<>在Python中意味着什么

[英]what does <> mean in Python

What is the meaning of <> in Python? Python中<>的含义是什么?

I have tried searching for it on Google but I cannot seem to get inside the search term... 我曾尝试在Google上搜索它,但我似乎无法进入搜索字词...

I have not seen this in any other language also otherwise I would have tried to find it. 我还没有看到任何其他语言,否则我会试图找到它。

<> is an alternate spelling of != , the inequality test operator. <>是不等式测试运算符!=的替代拼写。 IIRC, it has been removed in Python3. IIRC,它已在Python3中删除。

>>> "foo" <> "bar"
True
>>> "foo" <> "foo"
False

It is an obsolete inequality operator. 它是一个过时的不平等运营商。 See the Python documentation . 请参阅Python 文档

!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only. !=也可以写<>,但这是一种过时的用法,仅用于向后兼容。 New code should always use !=. 新代码应始终使用!=。

它与!=相同(“不等于”)

<> means not equal to . <>表示not equal to <> and != have the same meanings. <>!=具有相同的含义。

From the docs : 来自文档

The forms <> and != are equivalent; 形式<>和!=是等价的; for consistency with C, != is preferred; 为了与C一致,!=是首选; where != is mentioned below <> is also accepted. 其中!=如下所述<>也被接受。 The <> spelling is considered obsolescent. <>拼写被认为是过时的。

the <> operator is the same as != which means not equal to <>运算符与!=相同,表示不等于

if thing1 <> thing2:
   code here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM