在Python3.7执行这个语句
-bash-4.1$ python3
Python 3.7.4 (default, Jan 7 2020, 14:28:41)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a, b = "testerzhang!", "testerzhang!"
>>> a is b
False
在Python3.8执行这个语句
$ python3
Python 3.8.6 (default, Dec 1 2020, 11:41:32)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a, b = "testerzhang!", "testerzhang!"
>>> a is b
True
在Python2.7执行这个语句
$ python
Python 2.7.11 (default, Jun 14 2016, 20:26:18)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a, b = "testerzhang!", "testerzhang!"
>>> a is b
True
Python3.7究竟做了啥,编译器居然对感叹号做了优化,有时候有些诡异的问题可以多个版本测试下。
网友评论