Method isnumeric() of str class in Python

The isnumeric() method returns True if all the characters of a string literal are numeric in nature. This may include symbols for simple fractions like ¾ as well.Whereas the method isdecimal() returns False if the literal contains characters corresponding to fractions like U+00BC.

Str Updated 18 Nov 2019 1 min read

Method Name

isnumeric

Method Signature

isnumeric()

Parameters

None

Return Value

True if all the characters are numeric. False otherwise.

Overview

  • The isnumeric() method returns True if the string literal is entirely made-up of numeric characters. Otherwise, it returns False.
  • For an empty string isnumeric() returns False.

Note: isnumeric() returns True for any character representing vulgar fraction(s) like ¾, whereas isdecimal() returns False for such cases.

Example

python
# Example Python program that checks whether the characters of

# a Python string are all numeric

# Check the string literal and print the results

def numericCheck(literal):

    testResult      = platformNumber.isnumeric();

    print("The string literal \"%s\" is made up of all numeric digits:" %literal);

    print(testResult);

platformNumber  = "9\u00BE";

numericCheck(platformNumber);

platformNumber  = "1A";

numericCheck(platformNumber);

Output

Output
The string literal "9¾" is made up of all numeric digits:

True

The string literal "1A" is made up of all numeric digits:

False