【Python】Learn Python the hard way, ex8 格式化字符串
2015-10-07 09:34
666 查看
formatter = "%r %r %r %r" print formatter % (1, 2, 3, 4) print formatter % ("one", "two", "three", "four") print formatter % (True, False, False, True) print formatter % (formatter, formatter, formatter, formatter) print formatter % ( "I had this thing.", "That you could type up right.", "But it didn't sing.", "So I said goodnight." ) ''' Test Result: 1 2 3 4 'one' 'two' 'three' 'four' True False False True '%r %r %r %r' '%r %r %r %r' '%r %r %r %r' '%r %r %r %r' 'I had this thing.' 'That you could type up right.' "But it didn't sing." 'So I said goodnight.' '''
心得:
善用逗号,使得print语句变短,符合Python的编码风格
相关文章推荐
- python实例:backup 备份
- 【Python】Learn Python the hard way, ex7 字符串连接
- 【Python】Learn Python the hard way, ex6 格式化字符串,多行文本
- Python学习笔记<字符串Str>
- Python学习笔记<字符串Str>
- leetcode之Rotate Image
- 用python进行项目实训的计划
- 【Python】Learn Python the hard way, ex5 格式化字符串
- 和声搜索算法-python实现
- 克隆选择算法-python实现
- 细菌觅食算法-python实现
- 蝙蝠算法-python实现
- 人工免疫算法-python实现
- 人工鱼群算法-python实现
- 人工蜂群算法-python实现
- 粒子群优化算法-python实现
- 差分进化算法-python实现
- 简单遗传算法-python实现
- 【Python】Learn Python the hard way, ex4 使用变量
- python requests的安装与简单运用