How to wrap text to format text paragraph in Python

2 Answers

0 votes
import textwrap
  
s = """Python is a programming language that lets you work quickly 
       and integrate systems more effectively. The core of extensible programming 
       is defining functions. Python allows mandatory and optional arguments, 
       keyword arguments, and even arbitrary argument lists."""

print(textwrap.fill(s, width=40))




'''
run

Python is a programming language that
lets you work quickly         and
integrate systems more effectively. The
core of extensible programming
is defining functions. Python allows
mandatory and optional arguments,
keyword arguments, and even arbitrary
argument lists.

'''

 



answered Apr 26, 2019 by avibootz
0 votes
import textwrap

s = """Python is a programming language that lets you work quickly 
       and integrate systems more effectively. The core of extensible programming 
       is defining functions. Python allows mandatory and optional arguments, 
       keyword arguments, and even arbitrary argument lists."""

twrapper = textwrap.TextWrapper(width=40) 
words = twrapper.wrap(text=s) 
  
for element in words: 
    print(element) 




'''
run

Python is a programming language that
lets you work quickly         and
integrate systems more effectively. The
core of extensible programming
is defining functions. Python allows
mandatory and optional arguments,
keyword arguments, and even arbitrary
argument lists.

'''

 



answered Apr 26, 2019 by avibootz

Related questions

1 answer 152 views
152 views asked Aug 4, 2020 by avibootz
1 answer 249 views
249 views asked Aug 4, 2020 by avibootz
1 answer 193 views
1 answer 235 views
1 answer 174 views
...