Reduce need of backslash
Bengt Richter
bokr at oz.net
Sat Sep 27 11:57:45 EDT 2003
On Fri, 26 Sep 2003 16:33:25 +0200, Peter Otten <__peter__ at web.de> wrote:
>Nicolas Fleury wrote:
>
>> I was wondering if the need for \ could be reduce in the language. For
>> example, could a line ending with = or + could be automaticly considered
>> incomplete?
>
>Did you know about (...)?
>
>>>> ("alpha"
>... + "beta"
>... + "gamma"
>...
>... )
>'alphabetagamma'
>>>>
>
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
Regards,
Bengt Richter
More information about the Python-list
mailing list