How to wrap 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(text);
 
 
 
'''
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
...