首页 > 解决方案 > python - 删除每个使用开始和结束字符

问题描述

我可能很简单,使用正则表达式,我无法使用开始和结束字符删除一些字符。

string = 'this is my test (20)'

基本上我想在左括号之前打印。

this is my test

我试过分裂

string = '('.join(split[:0]))

不确定正确的语法,。

标签: pythonstringsplit

解决方案


使用splitandstrip删除字符串末尾的多余空格

print(string.split("(")[0].strip())


推荐阅读