Python3 isnumeric() Method
Description
The isnumeric() method checks whether a string consists only of numeric characters, which can be Unicode digits, full-width digits (double-byte), Roman numerals, or Chinese numeral characters.
Exponent-like characters such as superscript 2 and fraction-like characters such as one half also count as numeric.
# s = '½'
s = '\u00BD'
Syntax
Syntax of the isnumeric() method:
str.isnumeric()
Parameters
- none.
Return Value
Returns True if the string contains only numeric characters, otherwise False
Example
The following example demonstrates the isnumeric() method:
Example
#!/usr/bin/python3
str
=
"runoob2016"
(
str
.
isnumeric
(
)
)
str
=
"23443434"
(
str
.
isnumeric
(
)
)
The output of the above example is:
False
True
Unicode digits:
Example
#!/usr/bin/python3
#s = '²3455'
s
=
'\u00B23455'
(
s.
isnumeric
(
)
)
s = '½'
s
=
'\u00BD'
(
s.
isnumeric
(
)
)
a
=
"\u0030"
#unicode for 0
(
a.
isnumeric
(
)
)
b
=
"\u00B2"
#unicode for ²
(
b.
isnumeric
(
)
)
c
=
"10km2"
(
c.
isnumeric
(
)
)
The output of the above example is:
True
True
True
True
False
Python3 Strings