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"

--

--

--

Cloud Robotics Research Scientist at @iRobot

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Minti on Solana

Top 3 Features to Be on the Lookout When Searching for Vmware Backup

How do you solve a problem like developing….

Docker Notes

Quantumblack(McKinsey) Coding test

A Glimpse into The Future of Mobile App Engineering

Integrate HMS to Unity Game(Part I)

TO CREATE/LAUNCH AN APPLICATION USING TERRAFORM ON AWS USING EFS SERVICE

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
Ben Kehoe

Ben Kehoe

Cloud Robotics Research Scientist at @iRobot

More from Medium

Install Python into Mac / Windows / Linux Machine

The Switch Case Statement In Python

Loops in Python

10 Important Standard Python Library Modules