The isdecimal() function in python helps to check whether all the characters of a string are decimal or not. The function returns true if all the characters are decimal(0-9) otherwise returns false. This method is used on Unicode objects.
string.isdecimal()
The isdecimal() doesn't take any parameters. Decimal characters are those numbers having a base 10.
The return value is always a boolean value. If a string contains whitespaces, symbols, or alphabets this method will return False. In the case of an empty string, the function will return False.
Input | Return Value |
---|---|
if all are decimal | True |
if all are not decimal | False |
string = "12345"
print(string.isdecimal())
# contains alphabets
string = "123abc45"
print(string.isdecimal())
# contains alphabets and spaces
string = "An5 Hii 345"
print(string.isdecimal())
Output:
True False False
string = '12345'
print(string .isdecimal())
#s = '²1234'
string = '\u00B51234'
print(string .isdecimal())
# string = '½'
string = '\u00BD'
print(string .isdecimal())
Output:
True False False