January 2019
Beginner
318 pages
8h 23m
English
The dedent() is another function of the textwrap module. This function removes the common leading whitespaces from every line of your text.
The syntax for this function is as follows:
textwrap.dedent(text)
text is the text to dedent.
Now, we will see an example of dedent(). Create a dedent_example.py script and write the following content in it:
import textwrapstr1 = ''' Hello Python World \tThis is Python 101 Scripting language\n Python is an interpreted high-level programming language for general-purpose programming. '''print("Original: \n", str1)print()t = textwrap.dedent(str1)print("Dedented: \n", t)
Run the script and you will get the output as follows:
student@ubuntu:~/work$ python3 dedent_example.pyHello Python ...
Read now
Unlock full access