How to wrap and indent text in Python

1 Answer

0 votes
import textwrap

text = "Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace."

text = "\n".join(textwrap.wrap(text, 50)) # wrap: 50 characters

print(textwrap.indent(text, " " * 5)) # indent: 5 spaces
 
 
 
 
'''
run:
 
     Python is an interpreted, high-level, general-
     purpose programming language. Created by Guido van
     Rossum and first released in 1991, Python's design
     philosophy emphasizes code readability with its
     notable use of significant whitespace.
  
'''

 



answered Aug 4, 2020 by avibootz

Related questions

1 answer 250 views
250 views asked Aug 9, 2024 by avibootz
1 answer 254 views
254 views asked Aug 4, 2020 by avibootz
1 answer 284 views
2 answers 360 views
1 answer 358 views
...