在Python中替换字符串的一部分?

马库姆:

我使用正则表达式从网页中获取字符串,并且该字符串的一部分可能包含我想替换为其他内容的内容。这怎么可能呢?我的代码是这样的,例如:

stuff = "Big and small"
if stuff.find(" and ") == -1:
    # make stuff "Big/small"
else:
    stuff = stuff
jamylak:
>>> stuff = "Big and small"
>>> stuff.replace(" and ","/")
'Big/small'

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章