Reduce need of backslash

Peter Otten __peter__ at web.de
Mon Sep 29 08:37:40 CEST 2003


Bengt Richter wrote:

> Did you know the tokenizer concatenates white-space-separated string
> literals into a single literal? ;-)
> 
>>>> ("alpha"
> ...  "beta"
> ...  "gamma"
> ... )
> 'alphabetagamma'
> 
> Note the effect in code:
> 
>  >>> import dis
>  >>> f1 = lambda: ("alpha"
>  ...              + "beta"
>  ...              + "gamma"
>  ...              )
>  >>> f2 = lambda: ("alpha"
>  ...                "beta"
>  ...                "gamma"
>  ...              )
>  >>> dis.dis(f1)
>    1           0 LOAD_CONST               1 ('alpha')
>                3 LOAD_CONST               2 ('beta')
>                6 BINARY_ADD
>                7 LOAD_CONST               3 ('gamma')
>               10 BINARY_ADD
>               11 RETURN_VALUE
>  >>> dis.dis(f2)
>    1           0 LOAD_CONST               1 ('alphabetagamma')
>                3 RETURN_VALUE

No. Or I would have chosen another example :-)

But now you point it out I see it's used quite frequently in the library.

Peter


 





More information about the Python-list mailing list