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
I think
s.startswith('-') and s[1:].isdigit()
would be better to rewrite to:
s.replace('-', '').isdigit()
because s[1:] also creates a new string
But much better solution is
s.lstrip('+-').isdigit()