Is there any way to tell whether a string represents an integer (e.g., \'3\'
, \'-17\'
but not \'3.14\'
or \'asf
Uh.. Try this:
def int_check(a):
if int(a) == a:
return True
else:
return False
This works if you don't put a string that's not a number.
And also (I forgot to put the number check part. ), there is a function checking if the string is a number or not. It is str.isdigit(). Here's an example:
a = 2
a.isdigit()
If you call a.isdigit(), it will return True.