.isnumeric()
Published Sep 22, 2023
Contribute to Docs
.isnumeric()
is used to verify that the string variable consists of numerical characters only. Which means the string cannot contain a space, comma, dash, or any other characters that are not numerical.
Syntax
There are two ways of using this function:
str.isnumeric(str_variable)
str_variable.isnumeric()
Example
The following examples implement .isnumeric()
and will return True
:
print(str.isnumeric("2"))print(str.isnumeric("½"))print(str.isnumeric("2023"))
or
# Define the string variablesnum = "2"one_half = "½"year = "2023"# Show the resultsprint(num.isnumeric())print(one_half.isnumeric())print(year.isnumeric())
Codebyte Example
This example is runnable and demonstrates instances where non-numeric values are passed into the .isnumeric()
function:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours