tom
tom

Reputation: 261

What does the <> operator do in python?

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 answered before, search engines don't like punctuation.

Upvotes: 7

Views: 405

Answers (3)

fmark
fmark

Reputation: 58577

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

Upvotes: 7

Richard Lang
Richard Lang

Reputation: 73

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

Upvotes: 0

zwol
zwol

Reputation: 140569

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.

Upvotes: 17

Related Questions