Python String isnumeric()

The isnumeric() method checks if all the characters in the string are numeric.

Example


isnumeric() Syntax

The syntax of the isnumeric() method is:

string.isnumeric()

Here, isnumeric() checks if all characters in string are numeric or not.


isnumeric() Parameters

The isnumeric() method doesn't take any parameters.


isnumeric() Return Value

The isnumeric() method returns:

  • True -if all characters in the string are numeric
  • False -if at least one character is not a numeric

Example 1: Python isnumeric()

Output

True 
False

In the above example, we have used the isnumeric() method to check whether every character in symbol_number and text is numeric or not.

The method returns:

  • True - for symbol_number since every character in "012345" are numeric
  • False - for text since every character in "Python3" are not numeric

Example 2: isnumeric() with Other Numeric Types

Python treats mathematical characters like numbers, subscripts, superscripts, and characters having Unicode numeric value properties (like a fraction, roman numerals, currency numerators) as numeric characters.

The isnumeric() method returns True with these characters. For example:

Output

True
True

Here, we have used the isnumeric() method with strings that contain superscript and fraction.

  • superscript_string.isnumeric() -returns True because '²3455' contains all numeric characters.
  • fraction_string.isnumeric() - returns True because '½123' contains all numeric characters.