Python中是否存在“不相等”运算符?


问题内容

你怎么说不等于?

喜欢

if hi == hi:
    print "hi"
elif hi (does not equal) bye:
    print "no hi"

是否有等同于==“不平等”的东西?


问题答案:

使用!=。请参阅比较运算符。为了比较对象身份,可以使用关键字is及其否定词is not

例如

1 == 1 #  -> True
1 != 1 #  -> False
[] is [] #-> False (distinct objects)
a = b = []; a is b # -> True (same object)