什么<>运营商在python中做什么?

时间:2010-11-24 01:12:14

标签: python

我刚遇到这个here,总是这样使用:

if string1.find(string2) <> -1:
    pass

<>运营商做了什么,为什么不使用通常的==in

很抱歉,如果之前已经回答过,搜索引擎不喜欢标点符号。

3 个答案:

答案 0 :(得分:17)

http://docs.python.org/reference/expressions.html#notin说:

  

[运营商] <>!=是等效的;为了与C保持一致,!=是首选。 [...] <>拼写被视为过时。

答案 1 :(得分:7)

<>!=相同,但the <> form is deprecated。您的代码示例可以更清晰地写成:

if string2 not in string1:
    pass

答案 2 :(得分:0)

&LT;&GT;意味着大于或小于,基本上“不相等”。