![图片[1]-python编程如何删除字符-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5e8a837ce7cc3440.jpg)
Python中可以使用replace()方法删除指定字符。
Python replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。
replace()方法语法:
str.replace(old,new[,max])
参数
old — 将被替换的子字符串。
new — 新字符串,用于替换old子字符串。
max — 可选字符串, 替换不超过 max 次
示例:
s1=input('s1:')
s2=input('s2:')
foriins1:
ifiins2:
s1=s1.replace(i,'')
print(s1)
执行结果:


© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END



















































暂无评论内容