from textwrap import dedent def test(): # end first line with \ to avoid the empty line! s = """\ hello world """ print(repr(s)) print(repr(dedent(s))) test()