【笨方法学python】ex8 - 打印,打印

代码如下:

点击查看代码
# -*-coding:utf-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."
	) # 第三局双引号是因为使用了 %r ,%r 是为了 debug 和排错,而非输出好看的格式。

a = "%s"
print a % "中文" # %s 输出表示数据
b = "%r"
print b % "中文" # %r 输出原始数据

formatter1 = "%s %s %s %s"

print formatter1 % (1, 2, 3, 4)
print formatter1 % ('one', 'two', 'three', 'four')
print formatter1 % (True, False, False, True)
print formatter1 % (formatter, formatter, formatter, formatter)
print formatter1 % (
	'I had this thing.',
	"That you could type up right.",
	"But it didn't sing.",
	"So I said goodnight."
	)

执行结果:
image

posted @ 2022-10-05 03:48  TiramisuPS  阅读(28)  评论(0编辑  收藏  举报