Is there any way to tell whether a string represents an integer (e.g., \'3\', \'-17\' but not \'3.14\' or \'asf
\'3\'
\'-17\'
\'3.14\'
\'asf
>>> "+7".lstrip("-+").isdigit() True >>> "-7".lstrip("-+").isdigit() True >>> "7".lstrip("-+").isdigit() True >>> "13.4".lstrip("-+").isdigit() False
So your function would be:
def is_int(val): return val.lstrip("-+").isdigit()