Python运算符!=和“ is not”有什么区别?
在Python中,!=定义为不等于运算符。如果两端的操作数彼此不相等,则返回true;如果相等,则返回false。
>>> (10+2) != 12 # both expressions are same hence false False >>> (10+2)==12 True >>> 'computer' != "computer" # both strings are equal(single and double quotes same) False >>> 'computer' != "COMPUTER" #upper and lower case strings differ True
然而,不是运算符检查id()两个对象是否相同。如果相同,则返回false;如果不相同,则返回true
>>> a=10 >>> b=a >>> id(a), id(b) (490067904, 490067904) >>> a is not b False >>> a=10 >>> b=20 >>> id(a), id(b) (490067904, 490068064) >>> a is not b True
热门推荐
10 姥爷生日祝福语简短精辟
11 简短的高考祝福语精选
12 祝福语简短创意闺蜜
13 老公生日祝福语简短好看
14 结业蛋糕男生祝福语简短
15 妈妈生日祝福语简短温暖
16 升学祝福语简短的个性
17 送给姐姐简短的祝福语
18 迎新祝福语简短20字