format
# 指定{}的名字w,c,b,i
template = 'Hello {w}, Hello {c}, Hello , Hello {i}.'
world = 'World'
china = 'China'
beijing = 'Beijing'
imooc = 'imooc'
# 指定名字對(duì)應(yīng)的模板數(shù)據(jù)內(nèi)容
result = template.format(w = world, c = china, b = beijing, i = imooc)
print(result)
# ==> Hello World, Hello China, Hello Beijing, Hello imooc.
中間把大寫(xiě)賦值給小寫(xiě)的代碼可以取消嗎?
2021-10-04
可以不用,但是在下面要賦值給w,c,i
# 指定{}的名字w,c,b,i
template = 'Hello {w}, Hello {c}, Hello , Hello {i}.'
result = template.format(w = 'World', c = 'China', b = 'Beijing', i = 'imooc')
print(result)
# ==> Hello World, Hello China, Hello Beijing, Hello imooc.