What does the <> operator do in python?

后端 未结 3 1539
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 02:13

I just came across this here, always used like this:

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

What does the <> ope

相关标签:
3条回答
  • 2020-12-02 02:21

    <> is the same as != although the <> form is deprecated. Your code sample could be more cleanly be written as:

    if string2 not in string1:
        pass
    
    0 讨论(0)
  • 2020-12-02 02:22

    <> would mean greater than or less than, essentially 'not equal'.

    0 讨论(0)
  • 2020-12-02 02:30

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

    The [operators] <> and != are equivalent; for consistency with C, != is preferred. [...] The <> spelling is considered obsolescent.

    0 讨论(0)
提交回复
热议问题