首页 > 程序开发 > Web开发 > Python >

Learn Python The Hard Way学习(8) - 打印,还是打印

2012-06-21

[python]1.formatter = "%r %r %r %r"2.3.4.print formatter % (1, 2, 3, 4)5.print formatter % ("one", "two", "three", "four")6.print formatter % (True, False, False, True)7.pri...

[python]
1. formatter = "%r %r %r %r"
2.
3.
4. print formatter % (1, 2, 3, 4)
5. print formatter % ("one", "two", "three", "four")
6. print formatter % (True, False, False, True)
7. print formatter % (formatter, formatter, formatter, formatter)
8. print formatter % (
9. "I had this thing.",
10. "That you could type up right.",
11. "But it didn't sing.",
12. "So I said goodnight."
13. )

运行结果
1 2 3 4
'one' 'two' 'three' 'four'
True False False True www.2cto.com
'%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.'

加分练习
1. 检查并记录自己的错误。
2. 注意最后一行,既有单引号又有双引号,它们是怎么工作的?
默认使用单引号,如果字符串中有单引号就使用双引号。如果字符串中有双引号,还是默认使用单引号。

作者:lixiang0522

相关文章
最新文章
热点推荐