标签:
python 提取一段字符串中去数字
ss = “123ab45”
方法一:filter
filter(str.isdigit, ss)
别处copy的filter的用法:
# one
>>> filter(str.isdigit, ‘123ab45‘)
‘12345‘
#two
def not_empty(s): return s and s.strip() filter(not_empty, [‘A‘, ‘‘, ‘B‘, None, ‘C‘, ‘ ‘])
# 结果: [‘A‘, ‘B‘, ‘C‘]
方法二:正则表达式
s = re.findall("\d+",ss)[0] print s
标签:
原文地址:http://www.cnblogs.com/lovychen/p/5550670.html