Python的字典形式格式化字符

来源:互联网 发布:删除搜狗输入法云计算 编辑:程序博客网 时间:2024/06/05 12:02

方法一:

>>>phonebook = {'Beth': '9102',  'Alice': '2431', 'Cecil': '3258'}

>>>"Cecil's phone number is %(Cecil)s." % phonebook

"Cecil's phone number is 3258."

(摘自Python基础教程(第二版))


方法二:

>>> 'There are %(howmany)d %(lang)s Quotation Symbols' %  {'lang': 'Python', 'howmany': 3}
'There are 3 Python Quotation Symbols'
(摘自 core python programming)

原创粉丝点击