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 红包祝福语简短10字
18 周六早晨祝福语简短