int()

int('42') → 42; int('ff', 16) → 255.

n = int('42')
try:
    n = int('abc')
except ValueError:
    pass