leisurelicht/wtfpython-cn

Strings can be tricky sometimes/微妙的字符串 *中的疑问

zhjr2019 opened this issue · 1 comments

疑问1:所有长度为 0 和长度为 1 的字符串都被驻留.
以下是我测试的代码

Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 'ka'
>>> len(a)
2
>>> id(a)
1439701558472
>>> len('ka')
2
>>> id('ka')
1439701558472

长度为2的字符串也驻留了吗?

这里适用的是规则的第三条 字符串中只包含字母,数字或下划线时将会被驻留