1. What is the isnumeric() Function in Python?
The isnumeric() method is a built-in Python string function used to check whether every character in a string is a numeric character. If all characters represent numeric values (including Unicode-based numeric symbols) and the string is not empty, the method returns True. If even one character is non-numeric, Python returns False.
What makes isnumeric() special is its broad coverage of numeric characters. Unlike isdigit() or isdecimal(), this method also recognizes wider Unicode numerics such as fractions, superscripts, and special numeric characters.
2. Purpose of the isnumeric() Method
The isnumeric() method is especially useful when working with text data that may include different types of numeric symbols. It helps in:
- Validating whether a string contains numeric characters only
- Processing numeric input from multilingual sources
- Handling fractions, special numerics, and Unicode numeric characters
- Improving data cleaning workflows in text processing
If you need to check numbers beyond standard digits (0–9), isnumeric() is often the best choice.
3. Python isnumeric() Syntax Function
string.isnumeric()
Explanation: A simple and clean method — no arguments required.
4. Parameter Description: Python isidentifier() Method
| Parameter | Type | Description |
|---|---|---|
| None | – | The isnumeric() method does not accept parameters. |
Return Value
The method returns a Boolean value (True or False) based on the content of the string.
- Returns True → if the string is non-empty and every character is a numeric character
- False – if the string contains any letters, punctuation, spaces, symbols, or is empty.
5. Examples and Explanations of the Python isidentifier() Method
Example 1: String with Only Digit Characters
text = "123456"
print(text.isnumeric())
# Output: True
Explanation:
Every character in this string is a standard digit, so isnumeric() correctly returns True.
Example 2: String with Unicode Numeric Characters (Superscripts)
text = "²³¹"
print(text.isnumeric())
# Output: True
Explanation:
Superscripts like “²” and “³” are recognized as numeric characters in Unicode, so the method returns True.
Example 3: Unicode Fraction Characters
text = "½"
print(text.isnumeric())
# Output: True
Explanation:
Fraction symbols—such as ½—are considered numeric by Unicode, making isnumeric() more flexible than isdigit() or isdecimal().
Example 4: Digits Mixed with Letters
text = "123abc"
print(text.isnumeric())
# Output: False
Explanation:
The presence of alphabetic characters breaks the numeric requirement, resulting in False.
Example 5: Digits Containing Spaces
text = "123 456"
print(text.isnumeric())
# Output: False
Explanation:
Spaces are not numeric characters. Even though both parts contain digits, the full string fails the test.
Example 6: Numeric Characters Mixed with Symbols
text = "123⁴$"
print(text.isnumeric())
# Output: False
Explanation:
While “⁴” is numeric, the dollar sign $ is not, so the entire string is considered non-numeric.
Example 7: Empty String
text = ""
print(text.isnumeric())
# Output: False
Explanation:
For isnumeric() to return True, the string must contain at least one numeric character. An empty string always returns False.
Example 8: Digits from Other Scripts (e.g., Hindi Numerals)
text = "१२३" # Hindi digits for 123
print(text.isnumeric())
# Output: True
Explanation:
Python fully supports Unicode numeric characters, including digits from non-Latin scripts such as Hindi, Arabic, and more.
Summary Table: Python isnumeric() Examples
Below is a clean and structured version that explains how isnumeric() behaves with different kinds of characters, including Unicode digits, fractions, and superscripts.
| String | isnumeric() Result | Explanation |
|---|---|---|
| “123456” | True | Contains only standard numeric digits. |
| “²³¹” | True | Superscript Unicode characters are considered numeric. |
| “½” | True | Unicode fraction characters return True. |
| “123abc” | False | Alphabetic characters make the string invalid for isnumeric(). |
| “123 456” | False | Space is not a numeric character. |
| “123⁴$” | False | Contains a symbol ($), which isn’t numeric. |
| “” | False | Empty string always returns False. |
| “१२३” | True | Hindi (Devanagari) digits are valid numeric Unicode characters. |