python - 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
.
解决方案
Use .replace()
method.
Documentation - https://docs.python.org/3/library/stdtypes.html#str.replace
Eg.
>>>a = "a=alpha"
>>>a.replace("a=", "")
'alpha'
推荐阅读
- nix - 运行 Nix 安装的 Mailhog
- node.js - 无法到达 localhost:PORT 在 Node.js 中创建并表达
- amazon-web-services - 如何根据区域限制 AWS 访问?
- java - Java:如何将类数据类型数组转换为字符串数组?
- redirect - 用户登录重定向
- angular - Jenkins 将 @tmp 工作区文件夹用于 firebase,但我的管道失败了
- python - 导入包含其他模块的模块时出现 Python 问题
- python - 在 python 中使用两个熊猫系列绘制均值和 SD 图
- tensorflow - 循环神经网络 (LSTM) 的 PCA - 我也应该将 PCA 用于目标变量吗?
- javascript - Rails 6.1:Webpacker 找不到 application.js