Python - String isnumeric() Method


Advertisements

The string isnumeric() method is used to check whether all characters of the string are numeric or not. It returns true when all characters of the string are numeric, else returns false. Numeric characters belongs to numbers 0 - 9, exponential format (example- 5²) or raional number format (example- ½).

Syntax


string.isnumeric()

Example:

In the below example, isnumeric() method to used to check whether all characters of the string are numeric or not.

MyString = "12345"
print(MyString.isnumeric())

MyString = "5²"
print(MyString.isnumeric())

MyString = "½"
print(MyString.isnumeric())

Output

True

True

True

Example:

In the below example, isnumeric() method to used to check whether all characters of the unicode string object are numeric or not.

MyString = "\u0032"        #unicode for 5
print(MyString.isnumeric())

MyString = "\u0035\u00B2"  #unicode for 5²
print(MyString.isnumeric())

MyString = "\u00BD"        #unicode for ½
print(MyString.isnumeric())

Output

True

True

True





String Methods
Advertisements