Python String isnumeric()
Python String isnumeric() is used to check if given string contains only numeric characters or not.
isnumeric() method returns True if all the characters in the given string are numeric [0-9], otherwise the method returns False.
In this tutorial, we will learn the syntax and examples for isnumeric() method of String class.
Syntax
The syntax to call isnumeric() method on string x
in Python is
x.isnumeric()
Examples
In the following program, we take a string '314'
in x
, and check if this string x
contains only numeric characters using isnumeric()
method.
Example.py
x = '314'
result = x.isnumeric()
print(result)
Output
True
In the following program, we take a string '3.14'
in x
, and check if this string is numeric using isnumeric()
method. Since, the string contains period character .
which is non-numeric, isnumeric() returns False.
Example.py
x = '3.14'
result = x.isnumeric()
print(result)
Output
False
Conclusion
In this Python Tutorial, we learned how to check if given string contains only numeric characters, using String method – isnumeric().