The method isnumeric() checks whether the string consists of only numeric characters. This method is present only on unicode objects.
1 | The syntax of the method is : str .isnumeric() |
Key Points :
• There are no isdecimal() function parameters.
• The function isumeric() returns true if all string characters are numerical; otherwise, false is returned.
• There is something unique about numerics, which is that in Unicode, they can all be represented.
• Another benefit of the isumeric() approach is that it helps count numbers in a string.
• Decimal characters (such as 0,1,2), numbers (such as a subscript, superscript), and characters with
a numeric meaning attribute in Unicode (such as percentages, roman numerals, currency numerators) is always numerical.
We’ll be covering the following topics in this tutorial:
Return Value from isnumeric()
The isnumeric() method returns:
• This approach returns true if the string includes all the numerical characters.
• If the string has more than one non-numeric character (alphabet or a single character), it returns false.
Below is the python program to demonstrate the isnumeric() function:
1 2 3 4 | str = u "Since2012" ; print ( str .isnumeric()) str = u "9815618378" ; print ( str .isnumeric()) |
When we run above the program, the outcome is as follows:
False
True
How to use isnumeric()?
1 2 3 4 5 | str = '\u00B98156' if str .isnumeric() = = True : print ( 'All the Characters are Numeric.' ) else : print ( 'All Characters are not Numeric.' ) |
When we run above the program, the outcome is as follows:
All the Characters are Numeric.
Below are several other functions that we can use to work with string in Python 3