开发者

What does the <> operator do in python?

开发者 https://www.devze.com 2023-01-27 04:26 出处:网络
I just came across this here, always used like this: if string1.find(string2) <> -1: pass What does the <> operator do, and why not use the usual == or in?

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

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

What does the <> operator do, and why not use the usual == or in?

Sorry if that has been answ开发者_如何学编程ered before, search engines don't like punctuation.


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.


<> 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消