Write a Python program to remove existing indentation from all of the lines in a given text


The program uses the textwrap module in Python to manipulate text. The para variable is a multi-line string that contains information about the Python programming language. First, the program prints the original string para as it is.

Next, the program uses the dedent method from the textwrap module to remove the common leading whitespace from every line in para. The method returns a new string with the leading whitespaces removed, which is stored in the res variable. Finally, the program prints the resulting string stored in res.

Source Code

import textwrap
para = """
	Python is an interpreted, object-oriented programming languages. 
	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(para)
res = textwrap.dedent(para)
print(res)

Output


        Python is an interpreted, object-oriented programming languages.
        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 programming languages.
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