python3 is和==

'''
is 判断左右两端的数据是否是同一个内存地址
== 判断左右两端的数据是否一样
'''
# s1 = "alex"
# s2 = "alex"
# print(s1 == s2)
# print(s1 is s2) #str被放入小数据池

'''
复杂的字符串不会被放入小数据池
'''
# s1 = "alex"*10
# s2 = "alex"*10
# print(id(s1))
# print(id(s2))

'''
列表 不会被放入小数据池
'''
# lst1 = ["apple", "banana"]
# lst2 = ["apple", "banana"]
# print(lst1 == lst2)
# print(lst1 is lst2) #list不会被放入小数据池
上一篇:深浅拷贝


下一篇:Python之深浅拷贝