4

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?

1

3 Answers 3

12

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'.

Sign up to request clarification or add additional context in comments.

Comments

1

An alternative style:

print "my name is [%s], I like [%s] and I ask question on [%s]" % ( "xxx", "python", "stackoverflow") 

Comments

0
str_val = '''"my name is [%s]" ", I like [%s] " "and I ask question on [%s]" % ("xxx", "python", "stackoverflow")''' print(str_val) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.