1. is 是比较对象id是否相等,是否是同一对象,是否内存地址相同
2. ==是比较内容是否相等
a1 = "Hi"
b1 = "Hi"
a is b True
a== b True
a2 = "long sentence"
b2 = "long sentence"
a is b False
a== b True
python有string interning机制,对于较小的字符串,只保留一个副本。
1. is 是比较对象id是否相等,是否是同一对象,是否内存地址相同
2. ==是比较内容是否相等
a1 = "Hi"
b1 = "Hi"
a is b True
a== b True
a2 = "long sentence"
b2 = "long sentence"
a is b False
a== b True