小编pyr*_*rou的帖子

奇怪的结果在python中

有人可以在python 2.6.6上解释我这个奇怪的结果吗?

>>> a = "xx"
>>> b = "xx"
>>> a.__hash__() == b.__hash__()
True
>>> a is b
True # ok.. was just to be sure

>>> a = "x" * 2
>>> b = "x" * 2
>>> a.__hash__() == b.__hash__()
True
>>> a is b
True # yeah.. looks ok so far !

>>> n = 2
>>> a = "x" * n
>>> b = "x" * n
>>> a.__hash__() == b.__hash__()
True # still okay.. …
Run Code Online (Sandbox Code Playgroud)

python string identity

7
推荐指数
2
解决办法
270
查看次数

标签 统计

identity ×1

python ×1

string ×1