Python3 isnumeric() Method
Python 3 Tutorial
- Python3 Tutorial
- Python3 Introduction
- Python3 Environment Setup
- Python3 VScode
- Python3 Basic Syntax
- Python3 Basic Data Types
- Python3 Data Type Conversion
- Python3 Interpreter
- Python3 Comments
- Python3 Operators
- Python3 Numbers
- Python3 Strings
- Python3 Lists
- Python3 Tuples
- Python3 Dictionaries
- Python3 Sets
- Python3 Conditional Statements
- Python3 Loops
- Python3 First Program
- Python3 Comprehensions
- Python3 Iterators & Generators
- Python3 with
- Python3 Functions
- Python3 lambda
- Python Decorators
- Python3 Data Structures
- Python3 Modules
- Python __name__
- Python3 Input & Output
- Python3 File
- Python3 OS
- Python3 Errors & Exceptions
- Python3 OOP
- Python3 Namespace/Scope
- Python Virtual Environment
- Python Type Hints
- Python3 Standard Library
- Python3 Examples
- Python Quiz
Python3 Advanced Tutorial
- Python3 Reg Expressions
- Python3 CGI Programming
- Python MySQL - mysql-connector Driver
- Python3 MySQL Database Connection β PyMySQL Driver
- Python3 Network Programming
- Python3 SMTP Sending Email
- Python3 Multithreading
- Python3 XML Processing
- Python3 JSON Data Parsing
- Python3 Date & Time
- Python3 Built-in Functions
- Python MongoDB
- Python3 urllib
- Python uWSGI Installation & Configuration
- Python3 pip
- Python3 operator Module
- Python math Module
- Python requests Module
- Python random Module
- Python OpenAI
- Python Useful Resources
- Python AI Drawing
- Python statistics Module
- Python hashlib Module
- Python Quantitative Trading
- Python pyecharts Module
- Python selenium Library
- Python Web Scraping β BeautifulSoup
- Python Scrapy Library
- Python Markdown to HTML
- Python sys Module
- Python Pickle Module
- Python subprocess Module
- Python queue Module
- Python StringIO Module
- Python logging Module
- Python datetime Module
- Python re Module
- Python csv Module
- Python threading Module
- Python asyncio Module
- Python PyQt
- Python for Loop
- Python while Loop
Python3.x Python3 isnumeric() Method
Description
The isnumeric() method checks whether all characters in the string are numeric characters. Numeric characters include Unicode digits, fullwidth digits (double-byte), Roman numerals, and Han (Chinese) numerals.
Exponents like Β² and fractions like Β½ are also considered numeric.
s = 'Β½'
s = 'u00BD'
Syntax
Syntax for the isnumeric() method:
str.isnumeric()
Parameters
- None.
Return Value
Returns True if all characters in the string are numeric characters, otherwise returns False.
Example
The following examples demonstrate the use of the isnumeric() method:
Example
#!/usr/bin/python3
str="tutorial2016"
print(str.isnumeric())
str="23443434"
print(str.isnumeric())
The output of the above example is:
False
True
Unicode digits:
Example
#!/usr/bin/python3
#s = 'Β²3455'
s = 'u00B23455'
print(s.isnumeric())
# s = 'Β½'
s = 'u00BD'
print(s.isnumeric())
a = "u0030" # unicode for 0
print(a.isnumeric())
b = "u00B2" # unicode for Β²
print(b.isnumeric())
c = "10km2"
print(c.isnumeric())
The output of the above example is:
True
True
True
True
False
2 Notes
The difference between str.isdecimal() and str.isdigit().
The str.isdecimal() function only returns True for decimal numbers, while the str.isdigit() function returns True for other Unicode-supported characters as well.
For more details, you can use the following code to output:
import itertools
line = '-' * 37
print(line)
print("| β | isdigit | isdecimal | chr")
print(line)
for number in itertools.chain(range(0x30, 0x3A), range(0x0660, 0x066A), range(0x06F0, 0x06FA), range(0x07C0, 0x07CA), range(0x0966, 0x0970), range(0x09E6, 0x09F0), range(0x0A66, 0x0A70), range(0x0AE6, 0x0AF0), range(0x0B66, 0x0B70), range(0x0BE6, 0x0BF0), range(0x0C66, 0x0C70), range(0x0CE6, 0x0CF0), range(0x0D66, 0x0D70), range(0x0DE6, 0x0DF0), range(0x0E50, 0x0E5A), range(0x0ED0, 0x0EDA), range(0x0F20, 0x0F2A), range(0x1040, 0x104A), range(0x1090, 0x109A), range(0x17E0, 0x17EA), range(0x1810, 0x181A), range(0x1946, 0x1950), range(0x19D0, 0x19DA), range(0x1A80, 0x1A8A), range(0x1A90, 0x1A9A), range(0x1B50, 0x1B5A), range(0x1BB0, 0x1BBA), range(0x1C40, 0x1C4A), range(0x1C50, 0x1C5A), range(0x2070, 0x2071), range(0x2080, 0x2089), range(0x2460, 0x2474), range(0x2474, 0x2488), range(0x2488, 0x249C), range(0x249C, 0x24B0), range(0x24EA, 0x24F5), range(0x24F5, 0x2500), range(0x2776, 0x2780), range(0x2780, 0x278A), range(0x278A, 0x2794), range(0x2CFD, 0x2CFE), range(0x3007, 0x3008), range(0x3021, 0x302A), range(0x3038, 0x303B), range(0x303D, 0x303E), range(0x3192, 0x3196), range(0x3220, 0x3230), range(0x3251, 0x3260), range(0x3280, 0x328A), range(0x32B1, 0x32C0), range(0xA620, 0xA62A), range(0xA8D0, 0xA8DA), range(0xA900, 0xA90A), range(0xA9D0, 0xA9DA), range(0xAA50, 0xAA5A), range(0xABF0, 0xABFA), range(0xFF10, 0xFF1A)):
char = chr(number)
print(f"| {number:04X} | {str(char.isdigit()):7} | {str(char.isdecimal()):9} | {char}")
YouTip