这是我的程序:
import re
string = "I have 56 apples, Tom has 34 apples, Mary has 222 apples"
apple = re.findall(r'\d{1,100}', string)
print (apple)
结果是:
['56', '34', '222']
我想命名上面的三个数字,以便我可以进行一些计算。我还想命名第一个结果a
,第二个b
,第三个c
。然后计算a+b
or a+c
,类似的东西。谁能告诉我该怎么做。
如果re.findall
不能在这里解决我的情况,还有其他方法可以实现这个目标吗?