python教程(四)之字典(3.字典格式)

这个标题的理解应该是用字符串格式的方法设置字典

a={"bob":"friend","charly":"friend","herry":"normal","hermione":"girlfriend"}
print("hermione is my {hermione}".format_map(a))
#hermione is my girlfriend
#format_map是字典特有的格式设置方法,非常便利,下面再来一个例子

b='''

  
    
    
    {title}
    

  
  
    
'''
bInsert={"title":"DemoOne","href":"./static/index.css","divId":"app"} print(b.format_map(bInsert)) # # # # # DemoOne # # # #
# # # #这简直像是前端模板编程一样,在需要时可以插入一大段标签内容

你可能感兴趣的:(python,python)