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 出阁宴祝福语姐姐简短