On this page
textwrap.wrap
Prev: textwrap.TextWrapper | Up: textwrap
Rel: textwrap.dedent, textwrap.fill, textwrap.indent, textwrap.shorten
Ref: docs.python.org — textwrap.wrap
Tags: #public #python3 #stdlib #textwrap
Import
import textwrap
from textwrap import wrap
Signature & Overview
textwrap.wrap(text, width=70, **kwargs)
Wrap a single paragraph of text, returning a list of wrapped lines.
Usage
import textwrap
assert textwrap.wrap('alpha beta gamma', width=10) == ['alpha beta', 'gamma']
Gotchas
- Returns a
list[str]without trailing newlines.
REPL Inspect
from textwrap import wrap
help(wrap)
Linked from
Related notes
- tuts/python3/stdlib_module/textwrap/TextWrapper Linked here; links to this page; shared tags: #stdlib, #textwrap
- tuts/python3/stdlib_module/textwrap Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/textwrap/dedent Linked here; shared tags: #stdlib, #textwrap
- tuts/python3/stdlib_module/textwrap/fill Linked here; shared tags: #stdlib, #textwrap
- tuts/python3/stdlib_module/textwrap/indent Linked here; shared tags: #stdlib, #textwrap
- tuts/python3/stdlib_module/textwrap/shorten Linked here; shared tags: #stdlib, #textwrap
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib