Python isnumeric() function is used to check if all the characters in the string are numeric. This method returns True if all the characters are numeric (0-9), otherwise False.
string.isnumeric()
isnumeric() Return Value: True
-if all characters in the string are numeric or False
-if at least one character is not a numeric
Example isnumeric() Python String function
Simple example code checks if every character of the pin is numeric.
pin = "523"
print(pin.isnumeric())
print("Hello1".isnumeric())
print("123H".isnumeric())
Output:
Note: "-1"
and "1.5"
are NOT considered numeric values, because all the characters in the string must be numeric, and the -
and the .
are not.
Do comment if you have any doubts or suggestions on this Python function topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.