Loading

python中的is判断引用的对象是否一致,==判断值是否相等

python中的is判断引用的对象是否一致,==判断值是否相等

a = 10
b = 20
list = [1,2,3,4,5]
print(a in list)
print(b not in list)
a = 20
print(a in list)
print(a is b)
print('*'*20)
c = 'c'
d = 'c'
print(c is d) # True 这个是个变量缓存的概念
c = 'c'*10000
d = 'c'*10000
print(c is d) # False 字符串太长就不一致的
print(c==d) # True 这个值就是相等的了

 

posted @ 2018-03-05 19:45  stono  阅读(703)  评论(0编辑  收藏  举报