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




isdecimal( ) FUNCTION


isdecimal( ) Function


The isdecimal( ) Function is used to check if all the letters in the String are numbers or not.


i.e. The String should only consist of numbers (0 to 9) . Any values other than that will not be considered.


Example :


x = "6354"
if x.isdecimal():
    print("All the letters in the String are numbers")
else:
    print("No! Not all the letters in the String are numbers")


Output :



  All the letters in the String are numbers

In the above code , we have declared a String '6354' that has numbers only.


x = "6354"

java_Collections

So , to check, if all the letters in the String are numbers, we have used 'isdecimal( )' function.


if x.isalpha():
    print("All the letters in the String are alphabets")
else:
    print("No! Not all the letters in the String are alphabets")

And in this case , all the letters in the String are numbers. So , we got the below output .


All the letters in the String are numbers

Similarly , let us look at the next example .


Example :


x = "62.3"
if x.isdecimal():
    print("All the letters in the String are numbers")
else:
    print("No! Not all the letters in the String are numbers")


Output :



  All the letters in the String are numbers

In the above code , we have declared a String '62.3' that has a point '.' other than numbers.


x = "62.3"

java_Collections

So , to check, if all the letters in the String are numbers, we have used 'isdecimal( )' function.


if x.isdecimal():
    print("All the letters in the String are numbers")
else:
    print("No! Not all the letters in the String are numbers")

And in this case , there is a point '.' other than numbers. So , we got the below output .


No! Not all the letters in the String are numbers