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:
Case-Insensitive String Matching in Java
Python Modules
Python Inheritance
Python Set symmetric_difference_update()
Python Program to Display Powers of 2 Using Anonymous Function
Python Program to Check if a Number is Positive, Negative or 0
Python Program to Merge Mails
Python String replace()
Python Program to Sort a Dictionary by Value
Python zip()
Python round()
Python print()
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python while Loop
Java InputStream to String
Machine Learning with Python for everyone - Mark E.Fenner
Python Dictionary fromkeys()
Python iter()
Python Custom Exceptions
Python Program to Shuffle Deck of Cards
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Why String is Immutable in Java?
Python Program to Convert Celsius To Fahrenheit
Python Program to Find the Sum of Natural Numbers
Python Matrices and NumPy Arrays
Python Input, Output and Import
Python sleep()
Convert Character Array to String in Java
Python Program to Illustrate Different Set Operations
Python frozenset()
Python String isidentifier()
Python Program to Measure the Elapsed Time in Python