textwrap.indent()
textwrap.indent() is a Python function in the Textwrap Module category. Adds a prefix to the beginning of selected lines. The syntax is textwrap.indent(text, prefix, predicate=None). Returns: Indented string. A typical example: indented = textwrap.indent(code, " ") # Indent with 4 spaces. A close sibling is textwrap.wrap(), which wraps text into a list of lines, each at most `width` characters. A close sibling is textwrap.fill(), which similar to wrap() but joins the lines with newlines and returns a single string. A close sibling is textwrap.dedent(), which removes common leading whitespace from all lines (for multiline strings). A close sibling is textwrap.shorten(), which truncates text to fit within `width` characters, adding a placeholder. More about this category: Text wrapping — wrap, fill, dedent, indent, shorten. Related Textwrap Module entries: textwrap.wrap(), textwrap.fill(), textwrap.dedent(), textwrap.shorten(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.