你怎么说不相等呢?
就像
if hi == hi:
print "hi"
elif hi (does not equal) bye:
print "no hi"
是否有等价于==的东西表示“不相等”?
你怎么说不相等呢?
就像
if hi == hi:
print "hi"
elif hi (does not equal) bye:
print "no hi"
是否有等价于==的东西表示“不相等”?
当前回答
在Python中有两个运算符用于“不等于”条件-
a.) !=如果两个操作数的值不相等,则条件为真。 (a != b)是正确的。
b.) <>如果两个操作数的值不相等,则条件为真。 (a <> b)为真。这类似于!=操作符。
其他回答
您可以同时使用!=或<>。
但是,请注意!=在<>被弃用的地方是首选的。
使用!=或<>。Both代表不平等。
比较运算符<>和!=是同一运算符的交替拼写。!=是首选的拼写;<>是过时的。(参考:Python语言参考)
使用! =。参见比较运算符。对于比较对象标识,可以使用关键字is和其否定的is not。
e.g.
1 == 1 # -> True
1 != 1 # -> False
[] is [] #-> False (distinct objects)
a = b = []; a is b # -> True (same object)
您可以使用!=运算符来检查是否不相等。
此外,在Python 2中有<>操作符,它曾经做同样的事情,但在Python 3中已弃用。
不相等!= (vs equal ==)
你是在问这种事吗?
answer = 'hi'
if answer == 'hi': # equal
print "hi"
elif answer != 'hi': # not equal
print "no hi"
这个Python -基本操作符图表可能会有帮助。