Closed TinyHandsome closed 3 years ago
在 10.哪些情况下不需要续行符 中:
在多行文本注释中,续行符也是可以不写的,但是会变成\n。
text = '''talk is cheap, show me the code.'''
输出:'talk is cheap,\nshow me the code.'
'talk is cheap,\nshow me the code.'
在 11.用户无感知的小整数池 中
在同一行里,同时给两个变量赋同一值时,结果依然为False。
a = 257; b = 257 a is b
输出:False
False
在 12.神器的intern机制 中
如果一个字符串长度超过20个字符,不启动intern机制,这个数字好像不是20
s1 = "a"*100 s2 = "a"*100 s1 is s2
输出:True
True
s1 = "a"*10001 s2 = "a"*10001 s1 is s2
续行符那个我补充上了。 intern 机制那个,我在 Python 2 和 Python 3.6 中上都试过了是 20 。你是使用 Python 交互式模式运行的吗?还是在 IDE 中测试的?
我在jupyterlab中运行的。
在 10.哪些情况下不需要续行符 中:
text = '''talk is cheap, show me the code.'''
输出:
'talk is cheap,\nshow me the code.'
在 11.用户无感知的小整数池 中
a = 257; b = 257 a is b
输出:
False
在 12.神器的intern机制 中
s1 = "a"*100 s2 = "a"*100 s1 is s2
输出:
True
s1 = "a"*10001 s2 = "a"*10001 s1 is s2
输出:
False