Python String isnumeric() Method

11-02-23 Ahmed Obaid 896 0

​The isnumeric() function checks if all characters in a string are numeric characters. If all characters in the string are numeric characters, return the boolean value True. If at least one character is not a numeric character, it returns the boolean value False.


How to formulate it like this:


string. isnumeric()

Parameters: The isnumeric() function does not take any parameters.

return value:

True: if all characters in the string are numeric.

False: if the string contains at least one non-numeric character.

Errors and exceptions:

If a parameter is passed to the isnumeric() function, an error occurs.


 Example:


# isnumeric function example
# Define a variable
string = "12345"
#isnumeric function call
str = string.isnumeric() # returns True
# Print the result
print(str)
# Define a variable
string = "T12345"
#isnumeric function call
str = string.isnumeric() # returns False
# Print the result
print(str)

The output will be:


True
False

The isnumeric() function checks if a string is all numeric characters like integers, fractions etc. (provided they are written in encodingundefined Unicode).

 Example:


#Unicode Define a variable encoding
string = "\u00BE" # 3/4 Unicode equals defining a variable with an encoding
#isnumeric function call
str = string.isnumeric() # returns True
# Print the result
print(str)

 The output will be:


True

 External sources:

 Built-in functions - official Python documentation

 If you have any questions or concerns, leave them in the comments



Tags


Python python data types Python String string methods python String comparison functions in Python Python String isnumeric Method

Share page