The isdigit() 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.
x = "6354" if x.isdigit(): print("All the letters in the String are numbers") else: print("No! Not all the letters in the String are numbers")
In the above code, we have declared a String '6354' that has numbers only.
So, to check, if all the letters in the String are numbers, we have used 'isdecimal( )' function.
if x.isdigit(): 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, all the letters in the String are numbers. So, we got the below output.
Similarly, let us look at the next example.
x = "62.3" if x.isdigit(): print("All the letters in the String are numbers") else: print("No! Not 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.
So, to check, if all the letters in the String are numbers, we have used 'isdigit( )' function.
if x.isdigit(): 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.