The isnumeric() method in Python String class is used to check if all the characters in the string are numeric characters or not.
isnumeric() method returns true if all characters in the string are numeric characters and there is at least one character, false otherwise. Numeric characters include digits (0..9) and all characters that have the Unicode numeric value property like superscripts or subscripts (as example 26 and 42), fractions like ¼.
Python isnumeric method examples
1. Using isnumeric() method to check if all the characters are digits or not.
str = '345' print(str) print(str.isnumeric()) str = 'A12B' print(str) print(str.isnumeric())
Output
345 True A12B False
2. Using isnumeric() method with superscripts or subscripts. For such strings isnumeric() method returns true.
str = '2\u2076' print(str) print(str.isnumeric()) str = '4\u2082' print(str) print(str.isnumeric())
Output
26 True 42 True
3. Using isnumeric() method with characters that have Unicode numeric value property.
s = '\u246D' #CIRCLED NUMBER FOURTEEN ? print(s) print(s.isnumeric()) s = '\u2474' #PARENTHESIZED DIGIT ONE ? print(s) print(s.isnumeric()) s = '\u248C' # DIGIT FIVE FULL STOP ? print(s) print(s.isnumeric()) s = '\u24B0' #PARENTHESIZED LATIN SMALL LETTER U ? print(s) print(s.isnumeric())
Output
⑭ True ⑴ True ⒌ True ⒰ False
That's all for this topic Python String isnumeric() Method. If you have any doubt or any suggestions to make please drop a comment. Thanks!
>>>Return to Python Tutorial Page
Related Topics
You may also like-