代码如下:
#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