Python Programming Examples Tutorial Index

Python String Programs

This Python program demonstrates textwrap class functionality to format and wrap plain texts. It does the text formatting by adjusting the line breaks in the input paragraph, making the text well-formatted and beautiful.



Example:

#Importing the textwrap module
import textwrap

#Define a dummy text
texts = """This method wraps the input paragraph such that each line is at most width characters long in the paragraph. If the input has some content, it returns a list of lines as output."""

# Wrap the text.
wrapper = textwrap.TextWrapper(width=40)
word_list = wrapper.wrap(text = texts)

# Print output
for element in word_list:
        print(element)

Program Output:

This method wraps the input paragraph
such that each line is at most width
characters long in the paragraph. If the
input has some content, it returns a list
of lines as output.


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram