>>> number = 1520 >>> int(str(number)[:2]) 15
import math def first_n_digits(num, n): return num // 10 ** (int(math.log(num, 10)) - n + 1)