textwrap

Stdlib — TextPython 2.0+Intermediate

Text wrapping and filling to a given line width

Quick Info

Documentation
Official Docs
Python Version
2.0+
Dependencies
None — Python Standard Library
Install
Included with Python

Learn by Difficulty

Quick Example

python
import textwrap

text = "Python is a versatile programming language that is widely used for web development, data science, artificial intelligence, and automation."

print(textwrap.fill(text, width=40))
print()
print(textwrap.shorten(text, width=50))

The textwrap module is part of Python's standard library. Text wrapping and filling to a given line width.

Try in Playground

Tags

stdlibstringtext-processing