是否存在“不相等"的问题? Python中的运算符? [英] Is there a "not equal" operator in Python?

查看:87
本文介绍了是否存在“不相等"的问题? Python中的运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您怎么说不相等?

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

是否有等同于==的东西表示不相等"?

Is there something equivalent to == that means "not equal"?

推荐答案

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

Use !=. See comparison operators. For comparing object identities, you can use the keyword is and its negation is not.

例如

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

这篇关于是否存在“不相等"的问题? Python中的运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆