网站制作学习网Python→正文:python 字符串替换
字体:

python 字符串替换

Python 2022/4/10 9:50:56  点击:不统计

原载于:原文章%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

·上一篇:\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本 >>    ·下一篇:python 多线程 并发 >>
推荐文章
最新文章