Easy Tutorial
❮ Python Func Reload Python Func Sorted ❯

Python3 isnumeric() Method

Python3 String


Description

The isnumeric() method checks if a string consists only of numeric characters. Numeric characters include: Unicode numbers, full-width numbers (double-byte), Roman numerals, and Chinese numerals.

Exponents like ² and fractions like ½ are also considered numbers.

# s = '½'
s = '\u00BD'

Syntax

Syntax for the isnumeric() method:

str.isnumeric()

Parameters

Return Value

Returns True if all characters in the string are numeric, otherwise returns False.

Examples

The following examples demonstrate the isnumeric() method:

#!/usr/bin/python3

str = "tutorialpro2016"  
print (str.isnumeric())

str = "23443434"
print (str.isnumeric())

Output of the above examples:

False
True

Unicode Numbers:

#!/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())

Output of the above examples:

True
True
True
True
False

Python3 String

❮ Python Func Reload Python Func Sorted ❯