English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
If all characters in the string are numeric characters, the isnumeric() method will return True. If not, it will return False.
Numeric characters have the following properties:
Numeric_Type = decimal
Numeric_Type = 数字(Digit)
Numeric_Type = 数字(Numeric)
In Python, decimal characters (such as: 0,1,2 ..), numbers (such as: subscripts, superscripts) and characters with Unicode numeric properties (such as: decimals, Roman numerals, currency numerators) are considered numeric characters.
You can use unicode to write numbers and numeric characters in the program. For example:
# s = '½' s = '\u00BD'
The syntax of isnumeric() is
string.isnumeric()
isnumeric() method without any parameters
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.
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())
When running the program, the output is:
True True True False
#s = '²3455' s = '\u00B23455' if s.isnumeric() == True: print('All characters are numbers.') else: print('Not all characters are numbers.')
When running the program, the output is:
Not all characters are numbers.