Tutorial Study Image

Python isnumeric()

The isnumeric() function in python helps to check whether all the characters in the string are numeric characters. The function returns True if all the characters are numeric otherwise, it will return False.


string.isnumeric() 
 

isnumeric() Parameters:

The isnumeric() method doesn't take any parameters. Here the numeric type means it may contain decimal(0-9), digits (subscript, superscript), and Unicode numeric value property (fraction, roman numerals, currency numerators). Floating point(like 1.5) and negative values(like -1) are not numeric values.

isnumeric() Return Value

The return value is always a boolean value. If there encountered an alphabet, symbol, or an empty string then the function will return false.

Input Return Value
all numeric characters True
at least one non-numeric False

Examples of isnumeric() method in Python

Example 1: How isnumeric() works in Python?


string = '1234567'
print(string.isnumeric())

#string = '²3455'
string = '\u00B23455'
print(string.isnumeric())

# string = '½'
string = '\u00BD'
print(string.isnumeric())

string='program12'
print(string.isnumeric())
 

Output:


True
True
True
False

Example 2: How to use isnumeric()in Python?


#string = '²3455'
string = '\u00B23455'

if string.isnumeric() == True:
  print('String characters are numeric.')
else:
  print('String characters are not numeric.')
 

Output:


String characters are numeric.