textwrap.shorten()
textwrap.shorten() is a Python function in the Textwrap Module category. Truncates text to fit within `width` characters, adding a placeholder. The syntax is textwrap.shorten(text, width, *, fix_sentence_endings=False, break_long_words=True, break_on_hyphens=True, placeholder=" [...]"). Returns: Shortened string. A typical example: textwrap.shorten("Hello world!", width=10) # "Hello [...]". 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.indent(), which adds a prefix to the beginning of selected lines. More about this category: Text wrapping — wrap, fill, dedent, indent, shorten. Related Textwrap Module entries: textwrap.wrap(), textwrap.fill(), textwrap.dedent(), textwrap.indent(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.