my_str = ‘123and456’
number = filter(str.isdigit, my_str )
number = 123456
使用正则表达式:
import re
re.findall(r’\d+’, ‘hello 42 I’m a 32 string 30’)
[‘42’, ‘32’, ‘30’]
my_str = ‘123and456’
number = filter(str.isdigit, my_str )
number = 123456
使用正则表达式:
import re
re.findall(r’\d+’, ‘hello 42 I’m a 32 string 30’)
[‘42’, ‘32’, ‘30’]