a={"bob":"friend","charly":"friend","herry":"normal","hermione":"girlfriend"}print("hermione is my {hermione}".format_map(a))#hermione is my girlfriend#format_map是字典特有的格式设置方法,非常便利,下面再来一个例子
b='''
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>{title}</title>
<link rel="stylesheet" href="{href}">
</head>
<body>
<div id="{divId}"></div>
<!-- built files will be auto injected -->
</body>
</html>
'''
bInsert={"title":"DemoOne","href":"./static/index.css","divId":"app"}print(b.format_map(bInsert))# <html># <head># <meta charset="utf-8"># <meta name="viewport" content="width=device-width,initial-scale=1.0"># <title>DemoOne</title># <link rel="stylesheet" href="./static/index.css"># </head># <body># <div id="app"></div># <!-- built files will be auto injected --># </body># </html>#这简直像是前端模板编程一样,在需要时可以插入一大段标签内容