Python string Method - isnumeric()

www.igif‮.aedit‬com

The isnumeric() method is a built-in string method in Python that returns True if all characters in the string are numeric characters. Numeric characters include digits, fractions, subscripts, superscripts, Roman numerals, currency numerators, and some other characters. Otherwise, it returns False.

Here is the syntax of the isnumeric() method:

str.isnumeric()

The isnumeric() method does not take any arguments. It can be called on a string and returns a Boolean value.

Example:

# Example 1
string1 = "12345"
print(string1.isnumeric()) # Output: True

# Example 2
string2 = "12.34"
print(string2.isnumeric()) # Output: False

# Example 3
string3 = "½"
print(string3.isnumeric()) # Output: True

# Example 4
string4 = "IV"
print(string4.isnumeric()) # Output: True

# Example 5
string5 = "₹20"
print(string5.isnumeric()) # Output: False

In the above example, string1 contains only digits, so isnumeric() method returns True. string2 contains a decimal point which is not a numeric character, so isnumeric() method returns False. string3 contains a fraction character which is a numeric character, so isnumeric() method returns True. string4 contains Roman numerals which are numeric characters, so isnumeric() method returns True. string5 contains a currency symbol which is not a numeric character, so isnumeric() method returns False.