How should this function be changed to return \"123456\"
?
def f():
s = \"\"\"123
456\"\"\"
return s
UPDATE: Everyo
Try
import re
and then
return re.sub("\s+", "", s)
Don't use a triple-quoted string when you don't want extra whitespace, tabs and newlines.
Use implicit continuation, it's more elegant:
def f():
s = ('123'
'456')
return s
You might want to check this str.splitlines([keepends])
Return a list of the lines in the string, breaking at line boundaries. This method uses the universal newlines approach to splitting lines. Line breaks are not included in the resulting list unless keepends is given and true.
Python recognizes "\r", "\n", and "\r\n" as line boundaries for 8-bit strings.
So, for the problem at hand ... we could do somehting like this..
>>> s = """123
... 456"""
>>> s
'123\n456'
>>> ''.join(s.splitlines())
'123456'