当前位置:  首页>> 技术小册>> Python合辑4-130个字符串操作示例

Python中的段落格式

  1. import textwrap
  2. hamlet = '''\
  3. Lorum ipsum is the traditional Latin placeholder text, used when a designer needs a chunk of text for dummying up a layout.
  4. Journo Ipsum is like that, only using some of the most common catchphrases, buzzwords, and bon mots of the future-of-news crowd.
  5. Hit reload for a new batch. For entertainment purposes only.'''
  6. wrapper = textwrap.TextWrapper(initial_indent='\t' * 1,
  7. subsequent_indent='\t' * 2,
  8. width=40)
  9. for para in hamlet.splitlines():
  10. print(wrapper.fill(para))

Output:

  1. Lorum ipsum is the traditional Latin
  2. placeholder text, used when a designer
  3. needs a chunk of text for dummying up
  4. a layout.
  5. Journo Ipsum is like that, only using
  6. some of the most common catchphrases,
  7. buzzwords, and bon mots of the future-
  8. of-news crowd.
  9. Hit reload for a new batch. For
  10. entertainment purposes only.

该分类下的相关小册推荐: