How to add indentation to the first line of a string with Python

1 Answer

0 votes
import textwrap

s = '''
Python is an interpreted high-level general-purpose 
programming language. Its design philosophy emphasizes 
code readability with its use of significant indentation. 
'''


dedent_strip =  textwrap.dedent(s).strip()

result = textwrap.fill(dedent_strip, initial_indent='',  subsequent_indent=' ' * 4, width=50)

print(result)




'''
run:

Python is an interpreted high-level general-
    purpose  programming language. Its design
    philosophy emphasizes  code readability with
    its use of significant indentation.

'''

 



answered Sep 2, 2021 by avibootz
...