import textwrap
doc='''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.'''
print(textwrap.fill(doc,20)) #按指定宽度进行排版
# 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. print(textwrap.fill(doc,width=80)) #按指定宽度进行排版
# 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. print(textwrap.wrap(doc)) #默认长度最大为70
# ['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.']

Python_排版函数的更多相关文章

  1. Python_回调函数

    import os import stat def remove_readonly(func,path): #定义回调函数 os.chmod(path,stat.S_IWRITE) #删除文件的只读文 ...

  2. Python_匿名函数_47

    匿名函数 Eva_J 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数 #这段代码 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc ...

  3. Python_生成器函数进阶_39

    def generator(): print(123) content = yield 1 #content接收的是send传的值 print('=======',content) print(456 ...

  4. Python_匿名函数

    匿名函数:为了解决那些功能很简单的需求而设计的一句话函数. 代码如下: 1 正常函数: 2 3 def calc(n): 4 5 return n ** n 6 7 print(calc(10)) 8 ...

  5. Python_初识函数和返回值_22

    #len s = '金老板小护士' len(s) def my_len(): #自定义函数 i = 0 for k in s: i += 1 print(i) length = my_len() pr ...

  6. Python_初识函数

    为什么要用函数 现在python届发生了一个大事件,len方法突然不能直接用了... 然后现在有一个需求,让你计算'hello world'的长度,你怎么计算? 这个需求对于现在的你其实不难,我们一起 ...

  7. js的规范写法ES5(自己以后按照这样写)

    1.引号的使用,单引号' ' 优先(如果不是引号嵌套,不要使用双引号) 正常情况:console.log('hello there')        双引号转码: $("<div cl ...

  8. Menu的自己定义实现-------保卫萝卜造塔升级塔菜单实现

    cocos2dx原生的menu排版函数实现的非常无完整,像最主要的Item的排序要想做得略微美丽一些就须要我们自己实现. 对于Menu我们能够用两种方法来实现: 1.大神级别. 继承自Control, ...

  9. C语言实例解析精粹学习笔记——29

    题目: 将字符行内单字之间的空格平均分配插入到单字之间,以实现字符行排版.也就是输入一个英文句子,单词之间的空格数目不同,将这些空格数平均分配到单词之间,重新输出. 代码如下(是原书中配套的代码,只是 ...

随机推荐

  1. 【一天一道LeetCode】#24. Swap Nodes in Pairs

    一天一道LeetCode系列 (一)题目 Given a linked list, swap every two adjacent nodes and return its head. For exa ...

  2. struts2 easyui实现datagrid的crud

    最近两天因为项目需要,接触了easyui,要用它的datagrid实现crud.第一次做,花了一天时间才完成所有功能,昨天做另外一个模块,同样的功能只用了两个小时. 现在把第一次做datagrid时遇 ...

  3. RedHat系列软件管理(第二版) --源码包安装

    RedHat系列软件管理 --源码包安装 源码包特点: 拥有广泛的平台支持性,可以装在所有的类UNIX操作系统上,不用考虑CPU架构. 灵活性,可以在安装过程中指定特有的选项. 定制度非常高,可以自己 ...

  4. 嵌入式C快速翻转一个任何类型的数的二进制位

    unsigned char reverse_bits(unsigned char value) { unsigned char answer , i ; answer = 0 ; for(i = 1 ...

  5. 使用Material Design 应用主题

    自从去年Google推出Material Design这款设计语言后,新的设计规范越来越受开发者们的喜爱,这篇文章包括后续文章就是慢慢的介绍在App中使用Material Design界面主题.动画. ...

  6. XMPP系列(五)---文件传输

    xmpp中发送文件和接收文件的处理有些不太一样,接收文件处理比较简单,发送稍微复杂一些. 首先需要在XMPPFramework.h中添加文件传输类 //文件传输 //接收文件 #import &quo ...

  7. Java中如何封装自己的类,建立并使用自己的类库?

    from:http://blog.csdn.net/luoweifu/article/details/7281494 随着自己的编程经历的积累会发现往往自己在一些项目中写的类在别的项目中也会有多次用到 ...

  8. C语言之可变参实现scanf函数

    既然有printf函数可变参实现,那就一定有scanf函数的可变参实现.废话不多说,源码奉上: 本源码不过多分析,如要明白原理,请翻本博客以往的文章看说明. 欢迎关注新浪微博:http://weibo ...

  9. CoordinatorLayout

    CoordinatorLayout作为"super-powered FrameLayout"基本实现两个功能:  1.作为顶层布局  2.调度协调子布局 CoordinatorLa ...

  10. C语言算法---求鞍点

    题目:有一个3X4矩阵,要求输出其鞍点(行列均最大的值),以及它的行号和列号. int a[3][4] = {{123,94,-10,218},                          {3 ...