- is :比较的是对象的id
- ==:比较的是对象的值
- 对于list,dict,tuple,set 只要重新定义就会产生新的id
- 对于字符串,数值,都是同一个id
#coding=utf-8 # 数值 a=9 b=9 # True print a is b # 字符串 a="hhh" b="hhh" # True print a is b # 字典 a={'a':2} b={'a':2} # False print a is b
python中is和==的区别
最新推荐文章于 2024-12-27 14:39:59 发布