Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 578 Bytes

161.md

File metadata and controls

29 lines (23 loc) · 578 Bytes
@author jackzhenguo
@desc
@tag
@version 
@date 2020/02/28

字符串驻留

In [1]: a = 'something'
    ...: b = 'some'+'thing'
    ...: id(a)==id(b)
Out[1]: True

如果上面例子返回True,但是下面例子为什么是False:

In [1]: a = '@zglg.com'

In [2]: b = '@zglg'+'.com'

In [3]: id(a)==id(b)
Out[3]: False

这与Cpython 编译优化相关,行为称为字符串驻留,但驻留的字符串中只包含字母,数字或下划线。

[上一个例子](160.md) [下一个例子](162.md)