我需要帮助用 python 代码删除一些字符:
txt = 'Congo (Congo-Brazzaville)'
我可以删除从 ( 到 ) 开始的字符吗
这样之后的txt就像:'Congo'
试试re包:
re
>>> import re >>> txt = re.sub("\(.*\)", "", txt) >>> txt 'Congo '
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
点击生成二维码
我来说两句