Reputation: 360
is it possible to create a new line in a string in one's python code that does NOT effect output?
Like:
print "This
is
my
string"
But the output when the program is run would just be "This is my string"
Just for purposes of formatting the program in a more readable way for very long strings.
Upvotes: 0
Views: 1119
Reputation: 154
You could also add a comma after every print statement to print the next output on the same line :
print "This",
print "is",
print "my",
print "string"
Upvotes: 2
Reputation: 6281
You could use implicit string joining too:
print("this "
"is "
"my "
"string")
Upvotes: 5
Reputation: 122032
You can invoke explicit line joining, adding a backslash at the end of each line:
>>> print "this \
... is \
... my \
... string"
this is my string
Upvotes: 2