Multiline string literal preserves every symbol between opening and closing quotes, including indentation: def f(): return """ hello world """ f() # hello world A possible solution is to remove indentation, Python will still correctly parse the code: def f(): return """ hello world """ f() # hello world However, its difficult to read because it looks like the literal is outside of the function body but its not. So, a much better solution is not to break the indentation but instead remove it from the string content using textwrap.dedent: from textwrap import dedent def f(): return dedent(""" hello world """) f() # hello world 5.5K viewsedited 15:00