Python 字符串处理:去除两侧数字和空格
可以使用字符串的 strip() 方法去掉两侧的空格,并使用正则表达式去掉数字:
import re
test_str = '02101 HelloPython 10310'
result = re.sub(r'\d', '', test_str.strip())
print(result)
输出结果为:
HelloPython
原文地址: https://www.cveoy.top/t/topic/m9b5 著作权归作者所有。请勿转载和采集!