to_int(text, fallback=0) that converts a string to an integer, returning fallback when the text isn't a valid integer. Surrounding whitespace is fine (int handles it); '12.5' and 'abc' are not.to_int(' 42 ')42
Whitespace is tolerated by int().
to_int('12.5', -1)-1
A float string raises ValueError, so the fallback returns.
int(text) does the strict parsing for you.
except ValueError: return fallback.