{"id":24468,"date":"2021-10-17T18:43:40","date_gmt":"2021-10-17T13:13:40","guid":{"rendered":"https:\/\/python-programs.com\/?p=24468"},"modified":"2021-11-05T19:24:56","modified_gmt":"2021-11-05T13:54:56","slug":"program-for-python-string-isdecimal-method","status":"publish","type":"post","link":"https:\/\/python-programs.com\/program-for-python-string-isdecimal-method\/","title":{"rendered":"Program for Python String isdecimal() Method"},"content":{"rendered":"
In the previous article, we have discussed Python Program for gamma() Function<\/a> If all of the characters are decimals(0-9), the isdecimal() method returns True.<\/p>\n On unicode objects, this method is used.<\/p>\n Syntax:<\/strong><\/p>\n Parameters:\u00a0<\/strong>This function has no parameters.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Are you facing difficulties in finding all the methods that a string object can call in python? Have a glance at this Python String Method Examples<\/a> Tutorial & meet such challenges with ease.<\/p>\n In the previous article, we have discussed Python Program for gamma() Function isdecimal() Function in Python: If all of the characters are decimals(0-9), the isdecimal() method returns True. On unicode objects, this method is used. Syntax: string.isdecimal() Parameters:\u00a0This function has no parameters. Examples: Example1: Input: Given first string = “123456789_python” Given second string = “92567” …<\/p>\n
\nisdecimal() Function in Python:<\/strong><\/p>\nstring.isdecimal()<\/pre>\n
Given first string = \"123456789_python\"\r\nGiven second string = \"92567\"<\/pre>\n
The above given first string is : 123456789_python\r\nThe given first string after applying isdecimal() function: False\r\nThe above given second string is : 92567\r\nThe given second string after applying isdecimal() function: True<\/pre>\n
Given first string = \"\\u0039\" (#unicode for 9)\r\nGiven second string = \"92567\"<\/pre>\n
The above given first string is : 9\r\nThe given first string after applying isdecimal() function: True\r\nThe above given second string is : 92567\r\nThe given second string after applying isdecimal() function: True<\/pre>\n
Program for isdecimal() Function\u00a0in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Give the first string as static input and store it in a variable.\r\ngvn_fststr = \"123456789_python\"\r\n# Apply isdecimal() function to the given first string that returns a value\r\n# true if all of the characters are decimals(0-9).\r\n# Store it in another variable.\r\nrslt_str1 = gvn_fststr.isdecimal()\r\n# Print the given String\r\nprint(\"The above given first string is :\", gvn_fststr)\r\n# Print the above given String after applying isdecimal() function.\r\nprint(\"The given first string after applying isdecimal() function:\", rslt_str1)\r\n# Similarly do the same for other string and print the result string.\r\ngvn_scndstr = \"92567\"\r\nrslt_str2 = gvn_scndstr.isdecimal()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying isdecimal() function:\", rslt_str2)\r\n<\/pre>\n
The above given first string is : 123456789_python\r\nThe given first string after applying isdecimal() function: False\r\nThe above given second string is : 92567\r\nThe given second string after applying isdecimal() function: True<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Give the first string as user input using the input() function and store it in a variable.\r\ngvn_fststr = input(\"Enter some Random String = \")\r\n# Apply isdecimal() function to the given first string that returns a value\r\n# true if all of the characters are decimals(0-9).\r\n# Store it in another variable.\r\nrslt_str1 = gvn_fststr.isdecimal()\r\n# Print the given String\r\nprint(\"The above given first string is :\", gvn_fststr)\r\n# Print the above given String after applying isdecimal() function.\r\nprint(\"The given first string after applying isdecimal() function:\", rslt_str1)\r\n# Similarly do the same for other string and print the result string.\r\ngvn_scndstr = input(\"Enter some Random String = \")\r\nrslt_str2 = gvn_scndstr.isdecimal()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying isdecimal() function:\", rslt_str2)\r\n<\/pre>\n
Enter some Random String = goodmorning456288729\r\nThe above given first string is : goodmorning456288729\r\nThe given first string after applying isdecimal() function: False\r\nEnter some Random String = 90876123\r\nThe above given second string is : 90876123\r\nThe given second string after applying isdecimal() function: True<\/pre>\n
\n