'concatenating''strings'
Bengt Richter
bokr at oz.net
Thu Aug 8 14:54:50 EDT 2002
On 8 Aug 2002 20:26:02 +0200, Chris Liechti <cliechti at gmx.net> wrote:
>hwlgw at hotmail.com (Will Stuyvesant) wrote in
>news:cb035744.0208081004.589ed61 at posting.google.com:
>>>>> '''3'
>> KeyboardInterrupt
>>>>> # that did hang with the cursor on the next line so I had to press
>> CTRL-c
>
>you stared a triple quote string but not finished it.
>
>> Totally unimportant but unexpected behaviour.
>> Looks like you can not concatenate the empty string '' to 'something'
>> without using the + operator.
>
>thats documented behaviour:
>http://python.org/doc/current/ref/string-catenation.html
>
>likely stolen from C where this trick is important for macro magic. in
>python its useful for longs strings to split them over multiple lines,
>without including newlines (what a triple quote string would do)
But don't forget needing paren expression context to ignore new lines:
>>> 'x'
'x'
>>> (
... 'x'
... 'y'
... )
'xy'
>>> (
... 'x'
... 'y' # or indent and comment as desired
... )
'xy'
But as mentioned, triple quotes include the \n's
>>> '''
... x
... y
... '''
'\nx\ny\n'
Regards,
Bengt Richter
More information about the Python-list
mailing list