{"id":692,"date":"2024-12-02T05:45:53","date_gmt":"2024-12-02T05:45:53","guid":{"rendered":"https:\/\/itsmycode.com\/?p=692"},"modified":"2024-10-21T05:47:37","modified_gmt":"2024-10-21T05:47:37","slug":"python-string-isdecimal","status":"publish","type":"post","link":"https:\/\/itsmycode.com\/python-string-isdecimal\/","title":{"rendered":"Python String isdecimal()"},"content":{"rendered":"\n<p>The <strong>Python String isdecimal()<\/strong> method is a built-in function that returns true if all the characters in a string are decimal. If one of the characters is not decimal in the string, it returns false.<\/p>\n\n\n\n<p>In this article, we will learn about the <strong>Python String <code>isdecimal()<\/code><\/strong> method with the help of examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-isdecimal-syntax\">isdecimal() Syntax<\/h2>\n\n\n\n<p>The Syntax of&nbsp;<strong><code>isdecimal()<\/code><\/strong>&nbsp;method is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">string.isdecimal()<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-isdecimal-parameters\">isdecimal() Parameters<\/h2>\n\n\n\n<p>The&nbsp;<strong><code>isdecimal()<\/code><\/strong>&nbsp;method does not take any parameters.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-isdecimal-return-value\">isdecimal() Return Value<\/h2>\n\n\n\n<p>The&nbsp;<strong><code>isdecimal()<\/code><\/strong>&nbsp;method returns<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>True<\/code> if all the characters in a string are valid decimal characters.<\/li>\n\n\n\n<li><code>False<\/code> if one or more characters in a string are not decimal characters.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-1-working-of-isdecimal\">Example 1: Working of isdecimal()<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\n# Python3 program to demonstrate the use\n# of isdecimal() \n  \ns = \"12345\"\nprint(s.isdecimal())\n  \n# contains alphabets\ns = \"123Hello123\"\nprint(s.isdecimal())\n  \n# contains numbers and spaces\ns = \"12345 6789\"\nprint(s.isdecimal())<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>True\nFalse\nFalse<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-2-string-containing-digits-and-numeric-characters\">Example 2: String Containing digits and Numeric Characters<\/h2>\n\n\n\n<p>The superscript and subscript are considered as digit characters and not decimals. If the string contains subscript or superscript the isdecimal() method will returns False.<\/p>\n\n\n\n<p>Similarly, the roman numbers, currencies and fractions are considered as numeric numbers and not decimals. The isdecimal() will return False if it finds these characters.<\/p>\n\n\n\n<p>It is recommended to use <a href=\"https:\/\/itsmycode.com\/python-string-isdigit\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>isdigit() method<\/strong><\/a> and <strong>isnumeric() method<\/strong> to check if the characters are valid digits and numeric characters respectively.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n# Python3 program to demonstrate the use\n# of isdecimal() \n\n# vaid decimal  \ns = '12345'\nprint(s.isdecimal())\n\n# in case of digit\n#s = '\u00b2123'\ns = '\\u00B2123'\nprint(s.isdecimal())\n\n# incase of numeric\n# s = '\u00bd'\ns = '\\u00BD'\nprint(s.isdecimal())<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>True\nFalse\nFalse<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Python String isdecimal() method is a built-in function that returns true if all the characters in a string are decimal. If one of the characters is not decimal in the string, it returns false. In this article, we will learn about the Python String isdecimal() method with the help of examples. isdecimal() Syntax The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":693,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,23],"tags":[],"class_list":["post-692","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-string-methods"],"_links":{"self":[{"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/posts\/692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/comments?post=692"}],"version-history":[{"count":1,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/posts\/692\/revisions"}],"predecessor-version":[{"id":694,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/posts\/692\/revisions\/694"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/media\/693"}],"wp:attachment":[{"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/media?parent=692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/categories?post=692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/tags?post=692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}