I would like to suggest another solution using regx that spans two scenarios:
1.
Input = 'abcd45def05'
Output = 45 + 05 = 50
import re print(sum(int(x) for x in re.findall(r'[0-9]+', my_str)))
Note the β+β for one or more occurrences
2.
Input = 'abcd45def05'
Output = 4 + 5 + 0 + 5 = 14
import re print(sum(int(x) for x in re.findall(r'[0-9]', my_str)))
source share