现在的位置: 首页 > 综合 > 正文

python08 格式化打印

2013年09月07日 ⁄ 综合 ⁄ 共 524字 ⁄ 字号 评论关闭

来源:http://learnpythonthehardway.org/book/ex8.html

看下代码ex8.py

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."
)

你将看到下面结果

$ python ex8.py
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.'

抱歉!评论已关闭.