🚀 Supercharge your YouTube channel's growth with AI.
Try YTGrowAI FreePython String isnumeric() Function
Python String isnumeric() function returns True if all the characters in the input string are found to be of numeric type, else it returns False.
A numeric character can be of the following type:
- numeric_character=Decimal
- numeric_character=Digit
- numeric_character=Numeric
Syntax:
input_string.isnumeric()
isnumeric() arguments: The isnumeric() function dosen’t take any argument as input.
Python isnumeric() Examples
Example 1:
string = '124678953'
print(string.isnumeric())
Output:
True
Example 2:
string = 'Divas Dwivedi . 124678953'
print(string.isnumeric())
Output:
False
Example 3: Special Unicode characters as the input string
string1 = '\u00B23455'
print(string1)
print(string1.isnumeric())
Output:
ยฒ3455
True
Example 4:
string = "000000000001"
if string.isnumeric() == True:
print("Numeric input")
else:
print("Not numeric")
str = "000-9999-0110"
if str.isnumeric() == True:
print("Numeric input")
else:
print("Non numeric input")
Output:
Numeric input
Non numeric input
Access all Unicode numeric characters
The unicodedata module is used to fetch all the numeric Unicode characters.
import unicodedata
count_numeric = 0
for x in range(2 ** 16):
str = chr(x)
if str.isnumeric():
print(u'{:04x}: {} ({})'.format(x, str, unicodedata.name(str, 'UNNAMED')))
count_numeric = count_numeric + 1
print(f'Count of Numeric Unicode Characters = {count_numeric}')
Output:
0030: 0 (DIGIT ZERO)
0031: 1 (DIGIT ONE)
0032: 2 (DIGIT TWO)
.....
ff15: ๏ผ (FULLWIDTH DIGIT FIVE)
ff16: ๏ผ (FULLWIDTH DIGIT SIX)
ff17: ๏ผ (FULLWIDTH DIGIT SEVEN)
ff18: ๏ผ (FULLWIDTH DIGIT EIGHT)
ff19: ๏ผ (FULLWIDTH DIGIT NINE)
Count of Numeric Unicode Characters = 800
Conclusion
Thus, in this article, we have studied and implemented the isnumeric() function of Python String.
References
- Python isnumeric function
- Python String documentation


