textwrap wraps paragraphs to a width, adds prefixes, and removes common indentation from multiline strings. fill returns a ready paragraph, while wrap provides separate lines for additional processing.

from textwrap import dedent, fill, indent

message = dedent("""
    Python keeps code readable.
    Formatting output deserves the same care.
""").strip()

print(fill(message, width=36))
print(indent(message, prefix="> "))

How to use it safely

Set width for the destination rather than only the developer's terminal. Preserve paragraphs separately and take care with code, URLs, or characters whose display width differs. dedent removes only the common margin.

To strengthen the foundation, read Python collections guide and type hints guide.

The official Python documentation, accessed July 22, 2026, describes the API, edge cases, and version compatibility.