format函数 指定名称代码
教程上关于 format函数 指定对应名称的代码举例:
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.
和我使用的这种指定命名代码
template='Hello {w}, \nThank you {c1}, \nMerci {b}, \nDanke {c2}'
result=template.format(w='world',c1='china',b='beijing',c2='chongqing')
print(result)
都能达到相同的目的,他们在运算效率上有区别吗?