leisurelicht / wtfpython-cn

wtfpython的中文翻译/施工结束/ 能力有限,欢迎帮我改进翻译

Home Page:https://github.com/leisurelicht/wtfpython-cn/blob/master/CONTRIBUTING.md

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Section: Strings can be tricky sometimes/微妙的字符串 * 中常量折叠在3.7中已经迁移至新的AST 优化器

yopoing opened this issue · comments

您好,在拜读wtfpython的时候,发现在3.7的版本中有一些变化。其中,

'a' * 20 is 'aaaaaaaaaaaaaaaaaaaa'
True
'a' * 21 is 'aaaaaaaaaaaaaaaaaaaaa'
False

我的环境中是这样的:

Python 3.7.1 (default, Dec 14 2018, 13:28:58)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.

'a' * 20 is 'aaaaaaaaaaaaaaaaaaaa'
True
'a' * 21 is 'aaaaaaaaaaaaaaaaaaaaa'
True

查了下相关资料,在3.7版本中,常量折叠已经从窥孔优化器迁移至新的 AST 优化器,后者可以以更高的一致性来执行优化。 (由 Eugene Toder 和 INADA Naoki 在 bpo-29469bpo-11549 中贡献。)

多谢,我会把相关说明加入正文中。并将你加入贡献者名单中。