当前位置: 移动技术网 > IT编程>脚本编程>Python > Python replace方法并不改变原字符串

Python replace方法并不改变原字符串

2019年02月01日  | 移动技术网IT编程  | 我要评论

青岛杀人案,香港自由行报价,李耐阅的qq

直接给出结论:replace方法不会改变原字符串。

temp_str = 'this is a test'
print(temp_str.replace('is','is')
print(temp_str)
this is a test
this is a test

如果是需要对原字符串进行替换,可以这样写,重新赋值

a=a.replace(oldstr,newstr)
print(a)

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网