import math

def extract_digits(integer, digits=3, keep_sign=False):
    sign = 1 if not keep_sign else int(math.copysign(1, integer))
return abs(integer) % 10 ** digits * sign
Get last three digits of an integer