您的位置:首页 > 编程语言 > Python开发

001_017 Python 替换字符串中的子串string.template

2014-03-11 02:28 337 查看
代码如下:

#encoding=utf-8
print '中国'

#根据字典内容,替换被标记的字符串

import string

new_style=string.Template('this is $thing')

print new_style.substitute({'thing':5})
print new_style.substitute({'thing':'test some'})

old_style='this is %(thing)s'
print old_style%{'thing':5}


打印结果如下:

中国

this is 5

this is test some

this is 5
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐