书本练习题8print函数使用
%r 的使用 如果%r里面参数含有单引号和双引号,打印结果时会输出双引号,只含有一种引号时输出单引号,
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 ringht.",
"But it didn't sing.",
"So I said goodnight."
))
输出结果
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 ringht.' "But it didn't sing." 'So I said goodnight.'
最后面一行结果中 "But it didn't sing." 输出的双引号字符串,其他的是单引号,区别在于这个字符串里面还有单引号,结果输出了双引号字符串,