是否记录了确切的行为str.__mod__?
这两行代码按预期工作:
>>> 'My number is: %s.' % 123
'My number is: 123.'
>>> 'My list is: %s.' % [1, 2, 3]
'My list is: [1, 2, 3].'
Run Code Online (Sandbox Code Playgroud)
此行也按预期运行:
>>> 'Not a format string' % 123
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
Run Code Online (Sandbox Code Playgroud)
但是这条线是什么以及为什么它不会引发任何错误?
>>> 'Not a format string' % [1, 2, 3]
'Not a format string'
Run Code Online (Sandbox Code Playgroud)
聚苯乙烯
>>> print(sys.version)
3.3.2 (default, Aug 15 2013, …Run Code Online (Sandbox Code Playgroud)