x = '5' y = 'x5' try: int(x) int(y) except ValueError: # do stuff pass