Text Processing Modules

textwrap

Wrap or shorten plain text to a target character width, remove shared indentation with dedent(), and indent lines. The width is not a terminal display-cell or grapheme measurement; tabs and long-word options affect wrapping.

Formal Syntax & Structure

python syntaxpython
import textwrap

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import textwrapprint(textwrap.fill("red green blue", width=9))
Python Reference