# 指定{}的名字w,c,b,i
template = 'Hello {w}, Hello {c}, Hello {b}, Hello {i}.'
world = 'World'
china = 'China'
beijing = 'Beijing'
imooc = 'imooc'
# 指定名字对应的模板数据内容
result = template.format(w = world, c = china, b = beijing, i = imooc)
print(result)
# ==> Hello World, Hello China, Hello Beijing, Hello imooc.
中间把大写赋值给小写的代码可以取消吗?
可以不用,但是在下面要赋值给w,c,i
# 指定{}的名字w,c,b,i
template = 'Hello {w}, Hello {c}, Hello {b}, Hello {i}.'
result = template.format(w = 'World', c = 'China', b = 'Beijing', i = 'imooc')
print(result)
# ==> Hello World, Hello China, Hello Beijing, Hello imooc.