Table of Contents
The isnumeric() method returns True if all characters in a string are numeric characters. If not, it returns False.
A numeric character has following properties:
- Numeric_Type=Decimal
- Numeric_Type=Digit
- Numeric_Type=Numeric
In Python, decimal characters (like: 0, 1, 2..), digits (like: subscript, superscript), and characters having Unicode numeric value property (like: fraction, roman numerals, currency numerators) are all considered numeric characters.
You can write the digit and numeric characters using unicode in the program. For example:
# s = '½' s = '\u00BD'
The syntax of isnumeric() is
string.isnumeric()
1. isnumeric() Parameters
The isnumeric() method doesn’t take any parameters.
2. Return Value from isnumeric()
The isnumeric() method returns:
- True if all characters in the string are numeric characters.
- False if at least one character is not a numeric character.
3. Example 1: Working of isnumeric()
s = '1242323' print(s.isnumeric()) #s = '²3455' s = '\u00B23455' print(s.isnumeric()) # s = '½' s = '\u00BD' print(s.isnumeric()) s = '1242323' s='python12' print(s.isnumeric())
Output
True True True False
4. Example 2: How to use isnumeric()?
#s = '²3455'
s = '\u00B23455'
if s.isnumeric() == True:
print('All characters are numeric.')
else:
print('All characters are not numeric.')
Output
All characters are numeric.
Related posts:
Python String isidentifier()
String Processing with Apache Commons Lang 3
Python String isspace()
Python any()
Python vars()
Python staticmethod()
Adding a Newline Character to a String in Java
Python *args and **kwargs
Python Matrices and NumPy Arrays
Python Strings
Python Set clear()
Java – Generate Random String
Python Program to Check If Two Strings are Anagram
Python Program to Randomly Select an Element From the List
Python Program to Create Pyramid Patterns
Python Dictionary fromkeys()
Python Program to Merge Two Dictionaries
Python Set difference_update()
Python Program to Create a Countdown Timer
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python open()
Python compile()
Python List Comprehension
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Dictionary pop()
Python Program to Check Prime Number
Python setattr()
Python isinstance()
Python Program to Find Hash of File
Python Program to Parse a String to a Float or Int
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Program to Check Armstrong Number