Skip to main content

isnumeric()

The isnumeric() function is a method in Python that is used to check whether all the characters in a string are numeric digits (0-9). It returns True if all characters are numeric, and False otherwise.

Parameter Values

This function does not accept any parameters.

Return Values

The isnumeric() method returns a bool, either True or False.

How to Use isnumeric() in Python

Example 1:

The isnumeric() method returns True if all characters in the string are numeric (0-9) and there is at least one character, otherwise it returns False.

text = '12345'
print(text.isnumeric())
Example 2:

The isnumeric() method returns False if the string contains any non-numeric characters such as spaces or special symbols.

text = '12 345'
print(text.isnumeric())
Example 3:

The isnumeric() method handles negative numbers correctly, returning False if the string starts with a negative sign.

text = '-123'
print(text.isnumeric())