python - Why doesn't the + operator work between multi single line strings? -
this question has answer here:
i trying concatenate multi line string single line in python , it's giving me invalid syntax error.
authheader = '<header></header>' reqbody = '<s:envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">' + authheader + '''<s:body xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <getsnapshoturi xmlns="http://www.onvif.org/ver10/media/wsdl"><profiletoken>quality_h264</profiletoken></getsnapshoturi> </s:body> </s:envelope> '''
no need use +
operator concatenate strings want spread out on multiple lines better readability. this:
s = ( "my long string" "that spans multiple lines" )
the parser correctly deal , is part of python grammar (string literal concatentation. turning larger strings sequences of code ends being far more readable.
for more info, see python docs on strings states:
this feature particularly useful when want break long strings:
>>> text = ('put several strings within parentheses ' 'to have them joined together.') >>> text 'put several strings within parentheses have them joined together.'
Comments
Post a Comment