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 time Module
Python hex()
Array to String Conversions
Python String rsplit()
Python String isalpha()
Python Program to Trim Whitespace From a String
Python Program to Convert Celsius To Fahrenheit
Python List count()
Python Program to Illustrate Different Set Operations
Python Program to Print all Prime Numbers in an Interval
Python memoryview()
Python Program to Measure the Elapsed Time in Python
Python String isupper()
Python Dictionary get()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Program to Create a Long Multiline String
Python Type Conversion and Type Casting
Java – String to Reader
Python Program to Convert Kilometers to Miles
Python String rpartition()
Python repr()
Python Modules
Python String center()
Java Program to Permute All Letters of an Input String
Python String upper()
Python Dictionary pop()
Python Program to Multiply Two Matrices
Python Program to Count the Occurrence of an Item in a List
Python Set clear()
Python all()
Python List sort()
Python Program to Create Pyramid Patterns