B
B
Babamurat2020-05-29 21:59:07
Python
Babamurat, 2020-05-29 21:59:07

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

1 answer(s)
S
ScriptKiddo, 2020-05-29
@Babamurat

def is_digit(n):
    try:
        int(n)
        return True
    except ValueError:
        return  False

https://stackoverflow.com/a/28279781

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question