On Tue, 21 Aug 2012 17:47:28 +1000, Nick Coghlan <ncoghlan at gmail.com> wrote: > On Tue, Aug 21, 2012 at 11:55 AM, Ezio Melotti <ezio.melotti at gmail.com> wrote: > >> +String literals that are part of a single expression and have only > >> whitespace > >> +between them will be implicitly converted to a single string literal. > >> + > > > > > > Is it a string /literal/ they are converted to? > Yup: > > >>> ast.dump(compile('"hello world"', '', 'eval', flags=ast.PyCF_ONLY_AST)) > "Expression(body=Str(s='hello world'))" > >>> ast.dump(compile('"hello" " world"', '', 'eval', flags=ast.PyCF_ONLY_AST)) > "Expression(body=Str(s='hello world'))" > > > Anyway a simple ('foo' 'bar') == 'foobar' example might make this sentence > > more understandable. > > Added. I think it is an important and subtle point that this happens at "compile time" rather than "run time". Subtle in that it is not at all obvious (as this question demonstrates), and important in that it does have performance implications (even if those are trivial in most cases). So I think it would be worth saying "implicitly converted to a single string literal when the source is parsed", or something like that. --David
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4