Python String isnumeric() Method

The Python isnumeric() method is a string method that returns True if all the characters in a string are numeric (0-9), otherwise False. The method also considers exponents such as 3² and ¾ as numeric values.

Here are some examples of using the isnumeric() method:

# Example 1: A simple example of numeric testing using isnumeric() method[^3^][2]
str1 = "HumptyDumpty"
str2 = "314"
print(str1.isnumeric())
print(str2.isnumeric())

# Prints False
# Prints True


# Example 2: The isnumeric() method will return True if the string contains unicode numeric characters[^4^][3] [^5^][6]
numstr = 'u0034' # u0034 is 4
print(numstr.isnumeric())

# Prints True


numstr = 'u00BD' # u00BD is ½
print(numstr.isnumeric())

# Prints True


numstr = '¾'
print(numstr.isnumeric())

# Prints True


# Example 3: The isnumeric() method will return False if the string contains any non-numeric character[^1^][5]
txt = "565543a"
x = txt.isnumeric()
print(x)

# Prints False

If you have any questions about this code, you can drop a line in comment.

Comments

Popular posts from this blog

Python chr() Built in Function

Python float() Built in Function

Python bool() Built in Function

Python Printing Readable Results

Python exec() Built in Function