当前位置:编程学习 > python >>

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

[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.zzzyk.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

补充:Web开发 , Python ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,