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)
In [4]:
print('\n'.join(s_wrap_list))
In [5]:
print(textwrap.fill(s, 40))
In [6]:
print(textwrap.wrap(s, 40, max_lines=2))
In [7]:
print(textwrap.fill(s, 40, max_lines=2))
In [8]:
print(textwrap.fill(s, 40, max_lines=2, placeholder=' ~'))
In [9]:
print(textwrap.fill(s, 40, max_lines=2, placeholder=' ~', initial_indent=' '))
In [10]:
s = 'あいうえお、かきくけこ、12345,67890, さしすせそ、abcde'
In [11]:
print(textwrap.fill(s, 12))
In [12]:
s = 'Python is powerful'
In [13]:
print(textwrap.shorten(s, 12))
In [14]:
print(textwrap.shorten(s, 12, placeholder=' ~'))
In [15]:
s = 'Pythonについて。Pythonは汎用のプログラミング言語である。'
In [16]:
print(textwrap.shorten(s, 20))
In [17]:
s_short = s[:12] + '...'
print(s_short)
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))
In [21]:
print(wrapper.fill(s))