# x: The int number # n: Digit index def digit_extraction_by_index(x, n): return (abs(x) // (10 ** n)) % 10 print(digit_extraction_by_index(123, 0)) # 3 print(digit_extraction_by_index(123, 1)) # 2