How would you say does not equal?
Like
JavaScript
x
5
1
if hi == hi:
2
print "hi"
3
elif hi (does not equal) bye:
4
print "no hi"
5
Is there something equivalent to ==
that means “not equal”?
Advertisement
Answer
Use !=
. See comparison operators. For comparing object identities, you can use the keyword is
and its negation is not
.
e.g.
JavaScript
1
5
1
1 == 1 # -> True
2
1 != 1 # -> False
3
[] is [] #-> False (distinct objects)
4
a = b = []; a is b # -> True (same object)
5