笨方法学习Python-习题8:打印,打印
2017-10-19 10:32
676 查看
# coding=utf-8 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 did't sing.", "So I said goodnight.")) ''' 为什么 %r 有时打印出来的是单引号,而我实际用的是双引号? Python 会用最有效的方式打印出字符串,而不是完全按照你写的方式来打印。 这样做对于 %r 来说是可以接受的,因为它是用作 debug 和排错,没必要非打印出多好看的格式。 ''' ''' # 运行结果: 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 did't sing." 'So I said goodnight.' '''
相关文章推荐
- 笨方法学习Python-习题7:更多打印
- 笨方法学习Python-习题9:打印,打印,打印
- 笨方法学习Python-习题4:变量(variable)和命名
- 笨方法学习Python-习题20: 函数和文件
- 笨方法学习Python-习题18: 命名、变量、代码、函数
- 笨方法学习Python-习题24: 更多练习
- 笨方法学习Python-习题13: 参数、解包、变量
- 笨方法学习Python-习题29: 如果(if)
- 笨方法学习Python-习题33: While 循环
- 笨方法学习Python-习题22:到现在你学到了哪些东西?
- 笨方法学习Python-习题35: 分支和函数
- 笨方法学Python 习题 7: 更多打印
- 笨方法学习Python-习题30: Else 和 If
- 笨方法学习Python-习题25: 更多更多的练习
- 笨方法学习Python-习题3:数字和数学计算
- 笨方法学习Python-习题31: 作出决定
- 笨方法学习Python-习题10:那是什么?
- 笨方法学习Python-习题26: 恭喜你,现在可以考试了!
- 笨方法学习Python-习题11:提问
- 笨方法学习Python-习题19: 函数和变量