Python format

format()功能更强大,该函数把字符串当成一个模板,通过传入的参数进行格式化

formatter = "{} {} {} {}"
print(formatter.format(1, 2, 3, 4))
print(formatter.format("one", "two", "three", "four"))
print(formatter.format(True, False, True, False))

print(formatter.format(formatter, formatter, formatter, formatter))

输入结果
1 2 3 4
one two three four
True False True False
{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}


posted @ 2019-10-28 08:06  九虎君  阅读(154)  评论(0编辑  收藏  举报