Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 isnumeric() Method

Python3 isnumeric() Method

Python3 Strings Python3 Strings


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

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"

 

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

Python3 Strings Python3 Strings