English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Python Functions

Python Data Types

Python file operations

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Python string isnumeric() usage and example

Python string methods

If all characters in the string are numeric characters, the isnumeric() method will return True. If not, it will return False.

Numeric characters have the following properties:

  • Numeric_Type = decimal

  • Numeric_Type = number (Digit)

  • Numeric_Type = number (Numeric)

In Python, decimal characters (such as: 0,1,2 ..), numbers (such as: index, exponent) and characters with Unicode numeric properties (such as: decimal, Roman numerals, currency numerator) are considered numeric characters.

You can use unicode to write numbers and numeric characters in the program. For example:

# s = '½'
s = '\u00BD'

The syntax of isnumeric() is

string.isnumeric()

isnumeric() parameters

isnumeric() method without any parameters

isnumeric() return value

The isnumeric() method returns:

  • True If all characters in the string are numeric characters.

  • False If at least one character is not a numeric character.

Example1How does isnumeric() work?

s = '1242323
print(s.isnumeric())
#s = '²3455
s = '\u00B23455
print(s.isnumeric())
# s = '½'
s = '\u00BD'
print(s.isnumeric())
s = '1242323
s='python12
print(s.isnumeric())

When running the program, the output is:

True
True
True
False

Example2How to use isnumeric()?

#s = '²3455
s = '\u00B23455
if s.isnumeric() == True:
  print('All characters are numbers.')
else:
  print('Not all characters are numbers.')

When running the program, the output is:

Not all characters are numbers.

Python string methods