zoukankan      html  css  js  c++  java
  • Python_排版函数

     1 import textwrap
     2 doc='''Beautiful is better than ugly.
     3 Explicit is better than implicit.
     4 Simple is better than complex.
     5 complex is better than complicated.
     6 Flat is better than dense.
     7 Readability counts.
     8 Special cases arren't special enough to break the rules.
     9 Although Praticality beats purity.'''
    10 print(textwrap.fill(doc,20))    #按指定宽度进行排版
    11 # Beautiful is better
    12 # than ugly. Explicit
    13 # is better than
    14 # implicit. Simple is
    15 # better than complex.
    16 # complex is better
    17 # than complicated.
    18 # Flat is better than
    19 # dense. Readability
    20 # counts. Special
    21 # cases arren't
    22 # special enough to
    23 # break the rules.
    24 # Although Praticality
    25 # beats purity.
    26 
    27 print(textwrap.fill(doc,width=80))  #按指定宽度进行排版
    28 # Beautiful is better than ugly. Explicit is better than implicit. Simple is
    29 # better than complex. complex is better than complicated. Flat is better than
    30 # dense. Readability counts. Special cases arren't special enough to break the
    31 # rules. Although Praticality beats purity.
    32 
    33 print(textwrap.wrap(doc))   #默认长度最大为70
    34 # ['Beautiful is better than ugly. Explicit is better than implicit.', 'Simple is better than complex. complex is better than complicated.', "Flat is better than dense. Readability counts. Special cases arren't", 'special enough to break the rules. Although Praticality beats purity.']
  • 相关阅读:
    js将单个反斜杠转化为斜杠的问题
    HTML提供的6种空格
    JavaScript 内存管理
    JavaScript:4个常见的内存泄露
    正则多种匹配描述
    css3图片展示方式
    动态规划篇一:初见动态规划
    小球下落(Dropping Balls, Uva 679)
    破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)
    铁轨(rails, ACM/ICPC CERC 1997,Uva 514)
  • 原文地址:https://www.cnblogs.com/cmnz/p/6962419.html
Copyright © 2011-2022 走看看