Python String isdecimal()

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

Output

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

Output

True
False
False

Also Read:

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges