原载于:原文章%77w%77%2Ef%6F%72%61%73%70%2E%63n

python 字符串替换
通过原始方法进行字符串替换
oldstring = "原始字符串 网址是 siteurl"
newstring = oldstring.repalce("siteurl","www.forasp.cn")
print(newstring)

 
占位符
newstring = "原始字符串 网址: %s" %("www.forasp.cn")
print("替换后的字符", newstring)
 
对象替换
newstring = "原始字符串 网址: %s" %("www.forasp.cn")
print("替换后的字符", newstring)
 
模板字符串替换
from string import Template
oldstring = Template("原始字符串 网址: $site")
newstring = oldstring.substitute(site="www.forasp.cn")
print("替换后的字符串", newstring)

http://%77%77%77%2E%66%6F%72%61%73%70%2E%63%6E