January 2019
Beginner
318 pages
8h 23m
English
This function of the textwrap module is used truncate the text to fit in the specified width. For example, if you want to create a summary or preview, use the shorten() function. Using shorten(), all the whitespaces in your text will get standardized into a single space.
The syntax for this function is:
textwrap.shorten(text, width)
Now we will see an example of shorten(). Create a shorten_example.py script and write the following content in it:
import textwrapstr1 = "Python is an interpreted high-level programming language for general-purpose programming. Created by Guido van Rossum and first released in 1991, \n\nPython has a design philosophy that emphasizes code readability, notably using significant whitespace." ...
Read now
Unlock full access