Python: Remove existing indentation from all of the lines in a given text
Python String: Exercise-27 with Solution
Write a Python program to remove existing indentation from all of the lines in a given text.
Sample Solution:
Python Code:
import textwrap
sample_text = '''
Python is a widely used high-level, general-purpose, interpreted,
dynamic programming language. Its design philosophy emphasizes
code readability, and its syntax allows programmers to express
concepts in fewer lines of code than possible in languages such
as C++ or Java.
'''
text_without_Indentation = textwrap.dedent(sample_text)
print()
print(text_without_Indentation )
print()
Sample Output:
Python is a widely used high-level, general-purpose, interpreted, dynamic programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java.
Flowchart:
Python Code Editor:
Previous: Write a Python program to display formatted text (width=50) as output.
Next: Write a Python program to add a prefix text to all of the lines in a string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/string/python-data-type-string-exercise-27.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics