练习代码
formatter = "{} {} {} {}"
print(formatter.format(1, 2, 3, 4))
print(formatter.format("one", "two", "three", "four"))
print(formatter.format(True, False, False, True))
print(formatter.format(formatter, formatter, formatter, formatter))
print(formatter.format(
"床前明月光",
"玻璃好上霜",
"要不及时擦",
"整不好就得脏"
))
Study Drills
- Do your checks, write down your mistakes, and try not to make the same mistakes on the next exercise. In other words, repeat the Study Drills from Exercise 7.
补充
- 没啥好说的,就是把字符串常量替换成了变量,再调用变量的
format
方法,原理都是相同的。
网友评论