Learn Python The Hard Way学习(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 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 right.' "But it didn't sing." 'So I said goodnight.'

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

你可能感兴趣的:(Learn Python The Hard Way学习(8) - 打印,还是打印)