Python String - isnumeric() Method
The Python 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 rational number format (example- ½).
Syntax
string.isnumeric()
Return Value
Returns True if all characters of the specified string are numeric, else returns False.
Example:
In the example below, isnumeric() method is 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())
The output of the above code will be:
True True True
Example:
In the example below, isnumeric() method is 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())
The above code will give the following output:
True True True
Recommended Pages
❮ Python String Methods