【问题标题】:What does the <> operator do in python?<> 运算符在 python 中的作用是什么?
【发布时间】:2010-11-24 01:12:13
【问题描述】:

我刚遇到这个here,一直这样使用:

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

&lt;&gt; 运算符有什么作用,为什么不使用通常的==in

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

【问题讨论】:

标签: python


【解决方案1】:

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

[运算符]&lt;&gt;!= 是等价的;为了与 C 保持一致,!= 是首选。 [...]&lt;&gt; 拼写被认为是过时的。

【讨论】:

    【解决方案2】:

    &lt;&gt;!= 相同,尽管 the &lt;&gt; form is deprecated。您的代码示例可以更简洁地编写为:

    if string2 not in string1:
        pass
    

    【讨论】:

    • not string2 in string1 不如string2 not in string1
    【解决方案3】:

    表示大于或小于,本质上是“不等于”。

    【讨论】:

    • 技术上小于或大于虽然无关紧要;)
    猜你喜欢
    • 2013-08-18
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-18
    • 2015-05-28
    • 2010-11-28
    • 2016-06-20
    相关资源
    最近更新 更多