Skip to main content
 首页 » 编程设计

python之如何在python中通过 strip 从字符串中删除中间字符

2025年05月04日21telwanggs

我想从输入 'x+y' 中删除“+”号,其中 x 和 y 是一个字符串(单个数字)并打印结果。

比如我输入5+7应该显示57

代码如下:

opr = input("Enter string").strip("+") 
print(opr) 

这段代码没有删除“+”号。

请您参考如下方法:

你可以使用替换

opr = input("Enter string").replace("+","") 
print(opr)