Answer the question
In order to leave comments, you need to log in
Why would the isdigit() string method return false on negative numbers?
Why would the isdigit() string method return false on negative numbers ?
eg:
/////////////////////////////////
string='-1'
print (string.isdigit())
result will be False
///////////////////////////////
How to get around this ?
thanks in advance !
Answer the question
In order to leave comments, you need to log in
def is_digit(n):
try:
int(n)
return True
except ValueError:
return False
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question