Python isdecimal

The Python isdecimal string function returns True if all the characters in a string are decimal characters. Otherwise, it returns False. In this section, we explain to you how to write isdecimal function with examples, and the syntax is

String_Value.isdecimal()

Python isdecimal function to check decimals

The following set of examples helps you understand this method. Within the fourth statement, 100.23 is returning false because there is no decimal representation for . symbol.

str1 = "100"
print("Output of str1 = ", str1.isdecimal())
 
str2 = "Python"
print("Output of str2 = ", str2.isdecimal())
 
str3 = "100and200"
print("Output of str3 = ", str3.isdecimal())
 
str4 = "100.23"
print("Output of str4 = ", str4.isdecimal())
 
str5 = "100 30"
print("Output of str5 = ", str5.isdecimal())
Python isdecimal function 1

In this String method example, we are using the method against the Unicode of different digits. Within the last statement, we used the Unicode of the $ symbol, which is why Python was returning false.

str1 = "\u0033" # Unicode of Digit 3
print("Output of str1 = ", str1.isdecimal())
 
str2 = "\u0039" # Unicode of Digit 9
print("Output of str2 = ", str2.isdecimal())
 
str3 = "\u06F1" #Extended Arabic-Indic Digit 1
print("Output of str3 = ", str3.isdecimal())
 
str4 = "\u07C9" # Niko Digit 9
print("Output of str4 = ", str4.isdecimal())
 
str5 = "\u096C" # Devanagari Digit 6
print("Output of str5 = ", str5.isdecimal())
 
str6 = "\u0024" # Unicode of $ Symbol
print("Output of str6 = ", str6.isdecimal())
Output of str1 =  True
Output of str2 =  True
Output of str3 =  True
Output of str4 =  True
Output of str5 =  True
Output of str6 =  False

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.