Python String isdecimal()

The isdecimal() method returns True if all characters in a string are decimal characters. If not, it returns False.

The syntax of isdecimal() is

string.isdecimal()

isdecimal() Parameters

The isdecimal() doesn't take any parameters.


Return Value from isdecimal()

The isdecimal() returns:

  • True if all characters in the string are decimal characters.
  • False if at least one character is not decimal character.

Example 1: Working of isdecimal()

s = "28212"
print(s.isdecimal())

# contains alphabets
s = "32ladk3"
print(s.isdecimal())

# contains alphabets and spaces
s = "Mo3 nicaG el l22er"
print(s.isdecimal())

When you run the program, the output will be:

True
False
False

The superscript and subscripts are considered digit characters but not decimals. If the string contains these characters (usually written using unicode), isdecimal() returns False.

Similarly, roman numerals, currency numerators and fractions are considered numeric numbers (usually written using unicode) but not decimals. The isdecimal() also returns False in this case.

There are two methods isdigit() and isnumeric() that checks whether the string contains digit characters and numeric characters respectively.

Learn more about isdigit() and isnumeric() methods.


Example 2: String Containing digits and Numeric Characters

s = '23455'
print(s.isdecimal())

#s = '²3455'
s = '\u00B23455'
print(s.isdecimal())

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

When you run the program, the output will be:

True
False
False