I have following code:
print "my name is [%s], I like [%s] and I ask question on [%s]" % ("xxx", "python", "stackoverflow")
I want to split this LONG line into multiple lines:
print
"my name is [%s]"
", I like [%s] "
"and I ask question on [%s]"
% ("xxx", "python", "stackoverflow")
Can you please provide the right syntax?
Use implied line continuation by putting everything within parentheses. This is the method recommended in Python's Style Guide (PEP 8):
print ("my name is [%s]"
", I like [%s] "
"and I ask question on [%s]"
% ("xxx", "python", "stackoverflow"))
This works because the Python interpreter will concatenate adjacent string literals, so "foo" 'bar'
becomes 'foobar'
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With