Python multi-line string literals with textwrap.dedent()

my_string = """This
is a
multi-line string"""
assert my_string == "This\nis a\nmulti-line string"
def get_string():
return """This
is a
multi-line string"""
assert get_string() == "This\n is a\n multi-line string"
def get_string():
return textwrap.dedent("""This
is a
multi-line string""")
assert get_string() == "This\n is a\n multi-line string"
def get_string():
return """\
This
is a
multi-line string"""
assert get_string() == " This\n is a\n multi-line string"
def get_string():
return textwrap.dedent("""\
This
is a
multi-line string""")
assert get_string() == "This\nis a\nmulti-line string"

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store