Method Name:
isnumeric
Method Signature:
isnumeric()
Parameters:
None
Return Value:
True if all the characters are numeric. False otherwise.
Overview:
- The isnumeric() method returns True if the string literal is entirely made-up of numeric characters. Otherwise, it returns False.
- For an empty string isnumeric() returns False.
Note: isnumeric() returns True for any character representing vulgar fraction(s) like ¾, whereas isdecimal() returns False for such cases.
Example:
# Example Python program that checks whether the characters of # a Python string are all numeric
# Check the string literal and print the results def numericCheck(literal): testResult = platformNumber.isnumeric(); print("The string literal \"%s\" is made up of all numeric digits:" %literal); print(testResult);
platformNumber = "9\u00BE"; numericCheck(platformNumber);
platformNumber = "1A"; numericCheck(platformNumber); |
Output:
The string literal "9¾" is made up of all numeric digits: True The string literal "1A" is made up of all numeric digits: False |