Method Isdecimal() Of Str Class In Python

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:

# 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:

The number is:9¾

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


Copyright 2020 © pythontic.com