In this section, we will learn about the textwrap Python module. This module provides the TextWrapper class that does all the work. The textwrap module is used for formatting and wrapping plain text. This module provides five main functions: wrap(), fill(), dedent(), indent(), and shorten(). We are going to learn these functions one by one now.
Text wrapping
The wrap() function
The wrap() function is used to wrap an entire paragraph in to a single string. The output will be a list of output lines.
The syntax is textwrap.wrap(text, width):
- text: Text to wrap.
- width: Maximum length allowed of a wrapped line. The default value is 70.
Now, we will see an example of wrap(). Create a wrap_example.py script and write the following...