{"id":3835,"date":"2020-02-29T14:19:45","date_gmt":"2020-02-29T14:19:45","guid":{"rendered":"https:\/\/www.askpython.com\/?p=3835"},"modified":"2026-09-29T16:26:55","modified_gmt":"2026-09-29T16:26:55","slug":"python-isdecimal-method","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python\/built-in-methods\/python-isdecimal-method","title":{"rendered":"The Python isdecimal() Method"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ll be introducing the python isdecimal() method in this tutorial. What if a user wants to check whether a given string contains a number or more specifically a decimal number or not? That can be a case when the user needs to convert the string to any other number types like integer or float or etc..<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a solution to this problem, <strong>Python<\/strong> comes with a built-in checking method, <code>isdecimal()<\/code>. Let us dig into the method and consequently understand how the method works and can be used accordingly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python isdecimal() Method Basics<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In general, the Python <code>isdecimal()<\/code> method directly checks whether all characters in the specified string are <strong>decimal<\/strong> characters or not. If yes, then the method returns <code>true<\/code> or else, returns <code>false<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax for Python isdecimal() method<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let us look at the syntax for the Python <code>isdecimal()<\/code> method, following which we can use the method.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; auto-links: true; title: ; notranslate\" title=\"\">\nstatus = str.isdecimal( )\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Here:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>str<\/code> is the string for which we are checking if it comprises of only decimal characters or not<\/li><li><code>status<\/code> stores the value returned by the <code>isdecimal()<\/code> method. That is <strong>true<\/strong> for all decimal characters or else, <strong>false<\/strong>.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: Here, status just holds either true or false, hence the type of status is <code>bool<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic example for the isdecimal() method<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">So here is a small example, which explains how to use the <code>isdecimal()<\/code> method for strings in <strong>Python<\/strong>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nstring1=&quot;1010&quot;\nprint(&quot;String is: &quot;,string1)\nprint(&quot;Result: &quot;,string1.isdecimal())\n\nstring2=&quot;a10101&quot;\nprint(&quot;String is: &quot;,string2)\nprint(&quot;Result: &quot;,string2.isdecimal())\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Output<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nString is:  1010\nResult:  True\nString is:  a10101\nResult:  False\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Here:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>String1<\/strong> consists of all decimal characters. Hence the <code>string1.isdecimal()<\/code> statement returns a <code>True<\/code> result<\/li><li>Whereas, <strong>string2<\/strong> has a character<strong> &#8216;a&#8217;<\/strong> in it. Due to the fact that <strong>string2<\/strong> doesn&#8217;t comprise of all decimal characters, the result, in this case, is <code>False<\/code>.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: The <code>isdecimal()<\/code> method in Python does not consider fractions, subscripts, superscripts, or any other <strong>Unicode<\/strong> implemented characters as a decimal or digit characters. Hence, for the presence of any of the numeric characters in a string, the method returns <code>False<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Python isdecimal() Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The code snippet below illustrates how the <code>isdecimal()<\/code> method in Python for strings works and what it returns.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# . is not considered as decimal character\nstring1=&quot;55.55&quot;\nprint(&quot;String is: &quot;,string1)\nprint(&quot;Result: &quot;,string1.isdecimal())\n\n#Pure character string\nstring2=&quot;AskPython&quot;\nprint(&quot;String is: &quot;,string2)\nprint(&quot;Result: &quot;,string2.isdecimal())\n\n#U+2082 unicode for subscript 2\nstring3=&quot;222\\u2082&quot;\nprint(&quot;String is: &quot;,string3)\nprint(&quot;Result: &quot;,string3.isdecimal())\n\n#U+2074 unicode for superscript 4\nstring4=&quot;34\\u2074&quot;\nprint(&quot;String is: &quot;,string4)\nprint(&quot;Result: &quot;,string4.isdecimal())\n\n#U+2152unicode for 1\/10 fraction\nstring5=&quot;10\\u2152&quot;\nprint(&quot;String is: &quot;,string5)\nprint(&quot;Result: &quot;,string5.isdecimal())\n\n#@ not considered as decimal character\nstring6=&quot;@1234&quot;\nprint(&quot;String is: &quot;,string6)\nprint(&quot;Result: &quot;,string6.isdecimal())\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Output<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"552\" height=\"369\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/isdecimal-example.png\" alt=\"Isdecimal Example\" class=\"wp-image-3839\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/isdecimal-example.png 552w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/02\/isdecimal-example-300x201.png 300w\" sizes=\"auto, (max-width: 552px) 100vw, 552px\" \/><figcaption>isdecimal() Example Output<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In the code above:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>For <strong>string1<\/strong>, the <code>isdecimal()<\/code> method returns a <code>false<\/code> value because of the dot(<strong>.<\/strong>) character present in between the digits. The method considers it not to be a decimal character<\/li><li>Again for <strong>string2<\/strong>, the string completely or purely consists of characters and hence the method returns a <code>false<\/code> result<\/li><li>For all the <strong>strings<\/strong>, <strong>string3<\/strong>, <strong>string4<\/strong> and <strong>string5<\/strong>. The <code>isdecimal()<\/code> method returns <code>false<\/code> because all of them contain Unicode values corresponding to non-digit numerical characters<\/li><li>At last for <strong>string6<\/strong> too, the method returns a <code>false<\/code> because of the fact that the string contains the &#8216;<strong>@<\/strong>&#8216; character, which again is a non-decimal character.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">So, in this tutorial, we learned about the built-in string <code>isdecimal()<\/code> method in <strong>Python<\/strong>, how it is used as well as how it works. For any questions feel free to comment below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li> https:\/\/www.journaldev.com\/24032\/python-string-isdecimal <\/li><li> <a href=\"https:\/\/stackoverflow.com\/questions\/22789392\/str-isdecimal-and-str-isdigit-difference-example\" target=\"_blank\" rel=\"noopener\">https:\/\/stackoverflow.com\/questions\/22789392\/str-isdecimal-and-str-isdigit-difference-example<\/a> <\/li><li> <a href=\"https:\/\/stackoverflow.com\/questions\/47113787\/difference-between-isnumeric-and-isdecimal-in-python\/47113836\" target=\"_blank\" rel=\"noopener\">https:\/\/stackoverflow.com\/questions\/47113787\/difference-between-isnumeric-and-isdecimal-in-python\/47113836<\/a> <\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction We&#8217;ll be introducing the python isdecimal() method in this tutorial. What if a user wants to check whether a given string contains a number or more specifically a decimal number or not? That can be a case when the user needs to convert the string to any other number types like integer or float [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":67717,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-3835","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-built-in-methods"],"_links":{"self":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/3835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=3835"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/3835\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media\/67717"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=3835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=3835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=3835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}