In [1]:
import textwrap

In [2]:
s = "Python can be easy to pick up whether you're a first time programmer or you're experienced with other languages"

In [3]:
s_wrap_list = textwrap.wrap(s, 40)
print(s_wrap_list)


['Python can be easy to pick up whether', "you're a first time programmer or you're", 'experienced with other languages']

In [4]:
print('\n'.join(s_wrap_list))


Python can be easy to pick up whether
you're a first time programmer or you're
experienced with other languages

In [5]:
print(textwrap.fill(s, 40))


Python can be easy to pick up whether
you're a first time programmer or you're
experienced with other languages

In [6]:
print(textwrap.wrap(s, 40, max_lines=2))


['Python can be easy to pick up whether', "you're a first time programmer or [...]"]

In [7]:
print(textwrap.fill(s, 40, max_lines=2))


Python can be easy to pick up whether
you're a first time programmer or [...]

In [8]:
print(textwrap.fill(s, 40, max_lines=2, placeholder=' ~'))


Python can be easy to pick up whether
you're a first time programmer or ~

In [9]:
print(textwrap.fill(s, 40, max_lines=2, placeholder=' ~', initial_indent='  '))


  Python can be easy to pick up whether
you're a first time programmer or ~

In [10]:
s = 'あいうえお、かきくけこ、12345,67890, さしすせそ、abcde'

In [11]:
print(textwrap.fill(s, 12))


あいうえお、かきくけこ、
12345,67890,
さしすせそ、abcde

In [12]:
s = 'Python is powerful'

In [13]:
print(textwrap.shorten(s, 12))


Python [...]

In [14]:
print(textwrap.shorten(s, 12, placeholder=' ~'))


Python is ~

In [15]:
s = 'Pythonについて。Pythonは汎用のプログラミング言語である。'

In [16]:
print(textwrap.shorten(s, 20))


[...]

In [17]:
s_short = s[:12] + '...'
print(s_short)


Pythonについて。P...

In [18]:
wrapper = textwrap.TextWrapper(width=30, max_lines=3, placeholder=' ~', initial_indent='  ')

In [19]:
s = "Python can be easy to pick up whether you're a first time programmer or you're experienced with other languages"

In [20]:
print(wrapper.wrap(s))


['  Python can be easy to pick', "up whether you're a first time", "programmer or you're ~"]

In [21]:
print(wrapper.fill(s))


  Python can be easy to pick
up whether you're a first time
programmer or you're ~