python初学篇:使用字典格式化字符串

1、使用字典格式化字符串

"""使用字典格式化字符串"""
# 在字符串模板中使用key
temp = '书名是: %(name)s, 价格是: %(price)010.2f, 出版社是: %(publish)s'
book = {'name': '疯狂讲义', 'price': 88.9, 'publish': '电子社'}
# 使用字典为字符串模板中的key传入值
print(temp % book)

 

posted @ 2019-11-29 16:00  蓝小六  阅读(472)  评论(0)    收藏  举报