Tutorial Study Image

Python isdecimal()

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() 
 

isdecimal() Parameters:

The isdecimal() doesn't take any parameters. Decimal characters are those numbers having a base 10.

isdecimal() Return Value

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

Examples of isdecimal() method in Python

Example 1: How isdecimal() works in Python?


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

Example 2: How isdecimal() works when string containing digits and numeric characters?


string = '12345'
print(string .isdecimal())

#s = '²1234'
string  = '\u00B51234'
print(string .isdecimal())

# string  = '½'
string  = '\u00BD'
print(string .isdecimal())
 

Output:


True
False
False