Function to print command-line usage for a program The following function works well to print out a help message for the program I have written. It prints a multi-line string message that describes the command line usage with some examples:

def usage():

    print(
        """
Usage examples:

Test deployment:
       $ fab [noinput] test deploy

Staging deployment:
       $ fab [noinput] staging deploy

Production deployment:
       $ fab [noinput] production deploy
""")


Unfortunately, in order to make the message look good in the output, the code block currently looks ugly with the string message making the indentation of the code look wrong. Is there a way to improve the code so that it is more readable, similar to the following code (which does not work - it is just an example) where the indentation is more readable?


def usage():

    print(
        """
        Usage examples:
        Test deployment:
            $ fab [noinput] test deploy
        Staging deployment:
          $ fab [noinput] staging deploy
        Production deployment:
          $ fab [noinput] production deploy
        """
    )



How can the readability be improved while still producing results that look good in the output?
You can use textwrap.dedent to remove common whitespace from the start of all lines in a multiline string:

&gt;&gt;&gt; import textwrap
&gt;&gt;&gt; print(textwrap.dedent(
        """
        Usage examples:
        Test deployment:
            $ fab [noinput] test deploy
        Staging deployment:
            $ fab [noinput] staging deploy
        Production deployment:
            $ fab [noinput] production deploy
        """
))

Usage examples:
Test deployment:
    $ fab [noinput] test deploy
Staging deployment:
    $ fab [noinput] staging deploy
Production deployment:
    $ fab [noinput] production deploy


As it says in the docs:


  This can be used to make triple-quoted strings line up with the left edge of the display, while still presenting them in the source code in indented form.