Write a Python program to display formatted text (width=35,70) as output


The program is written in the Python programming language and it uses the "textwrap" module to wrap the given text (paragraph) into multiple lines. The textwrap module provides some convenient functions to format the text into multiple lines.

  • The program starts by importing the "textwrap" module.
  • The next step is to define a string variable "para" which contains a long paragraph.
  • The program then uses the "fill" function from the "textwrap" module to wrap the text in the "para" string into multiple lines with a specified width. The first "fill" function call uses a width of 35 characters and the result is printed to the console using the "print" function.
  • The program repeats step 3 with a different width of 70 characters and the result is printed to the console using the "print" function.

Source Code

import textwrap
para = """
Python is an interpreted, object-oriented, high-level programming language that can be used for a wide variety of applications. Python is a powerful general-purpose programming language. First developed in the late 1980s by Guido van Rossum. Python is open source programming language. Guido van Rossum named it after the BBC Comedy TV series Monty Python’s Flying Circus
"""
print(textwrap.fill(para, width=35))
print("\n\n",textwrap.fill(para, width=70))

Output

 Python is an interpreted, object-
oriented, high-level programming
language that can be used for a
wide variety of applications.
Python is a powerful general-
purpose programming language. First
developed in the late 1980s by
Guido van Rossum. Python is open
source programming language. Guido
van Rossum named it after the BBC
Comedy TV series Monty Python’s
Flying Circus


  Python is an interpreted, object-oriented, high-level programming
language that can be used for a wide variety of applications. Python
is a powerful general-purpose programming language. First developed in
the late 1980s by Guido van Rossum. Python is open source programming
language. Guido van Rossum named it after the BBC Comedy TV series
Monty Python’s Flying Circus


Example Programs