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 152 views
152 views asked Aug 4, 2020 by avibootz
1 answer 193 views
2 answers 233 views
1 answer 235 views
1 answer 142 views
142 views asked Aug 9, 2024 by avibootz
...