Use !=. See comparison operators. For comparing object identities, you can use the keyword is and its negation is not.
e.g.
1 == 1 # -> True
1 != 1 # -> False
[] is [] #-> False (distinct objects)
a = b = []; a is b # -> True (same object)
Answer from tskuzzy on Stack OverflowUse !=. See comparison operators. For comparing object identities, you can use the keyword is and its negation is not.
e.g.
1 == 1 # -> True
1 != 1 # -> False
[] is [] #-> False (distinct objects)
a = b = []; a is b # -> True (same object)
Not equal != (vs equal ==)
Are you asking about something like this?
answer = 'hi'
if answer == 'hi': # equal
print "hi"
elif answer != 'hi': # not equal
print "no hi"
This Python - Basic Operators chart might be helpful.
What is the correct way to write a not equal Python condition? - TestMu AI Community
deprecated - Python not equal operator - Stack Overflow
Not equal operators
No .equals()?
Videos
Python 2 supports both, in python 3 the <> operator has been removed.
There is no difference between the two, but != is the preferred form.
From the official docs you linked
!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only. New code should always use !=.
I believe the rationale for originally accepting <> was that it looked more natural for someone coming from a mathematical background than the common C-style != operator.