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
{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
原文:https://www.cnblogs.com/dlmltao/p/11750222.html