{"id":24470,"date":"2021-10-17T18:44:47","date_gmt":"2021-10-17T13:14:47","guid":{"rendered":"https:\/\/python-programs.com\/?p=24470"},"modified":"2021-11-05T19:25:08","modified_gmt":"2021-11-05T13:55:08","slug":"program-for-python-string-isdigit-method","status":"publish","type":"post","link":"https:\/\/python-programs.com\/program-for-python-string-isdigit-method\/","title":{"rendered":"Program for Python String isdigit() Method"},"content":{"rendered":"
In the previous article, we have discussed Python Program for isdecimal() Function<\/a> If all of the characters are digits, the isdigit() method returns true; otherwise, it returns False.<\/p>\n Exponents, such as \u00b2, are also considered digits.<\/p>\n Syntax:<\/strong><\/p>\n Parameters: <\/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 isdecimal() Function isdigit() Function in Python: If all of the characters are digits, the isdigit() method returns true; otherwise, it returns False. Exponents, such as \u00b2, are also considered digits. Syntax: string.isdigit() Parameters: This function has no parameters. Examples: Example1: Input: Given first string = …<\/p>\n
\nisdigit() Function in Python:<\/strong><\/p>\nstring.isdigit()<\/pre>\n
Given first string = \"\\u0039\"\r\nGiven second string = \"\\u00B2\"<\/pre>\n
The above given first string is : 9\r\nThe given first string after applying isdigit() function: True\r\nThe above given second string is : \u00b2\r\nThe given second string after applying isdigit() function: True<\/pre>\n
Given first string = \"345.67\"\r\nGiven second string = \"python_12345\"<\/pre>\n
The above given first string is : 345.67\r\nThe given first string after applying isdigit() function: False\r\nThe above given second string is : python_12345\r\nThe given second string after applying isdigit() function: False<\/pre>\n
Program for isdigit() Function in 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 = \"\\u0039\"\r\n# Apply isdigit() function to the given first string that returns a value\r\n# true if all of the characters are digits, otherwise, it returns False.\r\n# Store it in another variable.\r\nrslt_str1 = gvn_fststr.isdigit()\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 isdigit() function.\r\nprint(\"The given first string after applying isdigit() function:\", rslt_str1)\r\n# Similarly do the same for other string and print the result string.\r\ngvn_scndstr = \"\\u00B2\"\r\nrslt_str2 = gvn_scndstr.isdigit()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying isdigit() function:\", rslt_str2)\r\n<\/pre>\n
The above given first string is : 9\r\nThe given first string after applying isdigit() function: True\r\nThe above given second string is : \u00b2\r\nThe given second string after applying isdigit() 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 isdigit() function to the given first string that returns a value\r\n# true if all of the characters are digits, otherwise, it returns False.\r\n# Store it in another variable.\r\nrslt_str1 = gvn_fststr.isdigit()\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 isdigit() function.\r\nprint(\"The given first string after applying isdigit() 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.isdigit()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying isdigit() function:\", rslt_str2)\r\n<\/pre>\n
Enter some Random String = 345.67\r\nThe above given first string is : 345.67\r\nThe given first string after applying isdigit() function: False\r\nEnter some Random String = python_12345\r\nThe above given second string is : python_12345\r\nThe given second string after applying isdigit() function: False<\/pre>\n
\n