首页 > 解决方案 > Is there a method to strip specific letter form a string

问题描述

Is there a method to strip specific letter form a string? I want to strip some letters from a string. For example, strip a= from a=alpha and strip b= from b=bravo. I have tried the normal strip method but the output would be lph and ravo while the targets are alpha and bravo.

标签: pythonpython-3.x

解决方案


Use .replace() method.
Documentation - https://docs.python.org/3/library/stdtypes.html#str.replace

Eg.

>>>a = "a=alpha"
>>>a.replace("a=", "")
'alpha'

推荐阅读