Method isdecimal() of str class in Python

For a string literal, the method isdecimal() returns True if it is composed of all decimal characters. For characters corresponding to simple fractions like 3/4 it returns False.

Str Updated 18 Nov 2019 1 min read

Method Name

isdecimal

Method Signature

isdecimal()

Parameters

None

Return Value

True, if a string is made of all decimal digits, else False.

Overview

  • The method isdeimcal(), returns True if the string literal is made up of all decimal digits. Else the method returns False. For example, presence of Unicode characters for simple fractions like ¾ or any other non-decimal characters will make the isdeimcal() to return False.
  • For an empty string isdeimcal() returns False.

Example

python
# Example Python program that tests whether a string is made of all decimal characters

# A numeric string with a simple three quarters

platformNumber  = "9\u00BE";

print("The number is:%s"%platformNumber);

isDecimalNum = platformNumber.isdecimal();

print("The literal %s is made of all decimal characters:%s"%(platformNumber, isDecimalNum))

Output

Output
The number is:9¾

The literal 9¾ is made of all decimal characters:False