Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




isnumeric( ) FUNCTION


isnumeric( ) Function


The isnumeric( ) Function is used to check if all the characters of the String are numeric.


Say, there is a situation, where you have a number. But you need to store as a String.


In such cases, you can use isnumeric( ) Function to check if all the characters are numbers or not.


Example :


x = "249393854"
if x.isnumeric():
    print("All the characters in the String are numbers")
else:
    print("No not all the characters in the String are numbers")


Output :



  All the characters in the String are numbers

In the above code, we have declared a String '249393854' which has only numbers and assigned it to a variable 'x'.


x = "249393854"

java_Collections

Now, to check, if all are numbers in the above String. We have used the isnumeric() Function.


if x.isnumeric():
    print("All the characters in the String are numbers")

Now since, all are numbers in the above String. The below output is printed.


All the characters in the String are numbers

Let us look at the second example, where the String has numbers and alphabets/letters.


Example :


x = "24A"
if x.isnumeric():
    print("All the characters in the String are numbers")
else:
    print("No not all the characters in the String are numbers")


Output :



  No not all the characters in the String are numbers

In the above code, we have declared a String '24A' which is a combination of numbers as well as alphabet.


x = "24A"

java_Collections

Now, to check, if all are numbers in the above String. We have used the isnumeric( ) Function.


if x.isnumeric():
    print("All the characters in the String are numbers")			
else:
    print("No not all the characters in the String are numbers")

And since, not all the elements are numbers, the control comes to the 'else' part printing the below output.


No not all the characters in the String are numbers