{"id":24669,"date":"2021-10-25T09:06:11","date_gmt":"2021-10-25T03:36:11","guid":{"rendered":"https:\/\/python-programs.com\/?p=24669"},"modified":"2021-11-05T19:15:26","modified_gmt":"2021-11-05T13:45:26","slug":"python-string-isnumeric-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-string-isnumeric-method-with-examples\/","title":{"rendered":"Python String isnumeric() Method with Examples"},"content":{"rendered":"
In the previous article, we have discussed Python Program for help() Function with Examples<\/a> If all of the characters are numeric (0-9), the isnumeric() method returns True; otherwise, it returns False.<\/p>\n Exponents such as \u00b2 and \u00be are also considered numeric values.<\/p>\n Because all of the characters in the string must be numeric, “-2” and “1.4” are NOT<\/strong> considered numeric values.<\/p>\n And the ‘-‘, ‘.’ are not the numeric values.<\/p>\n Numeric characters in Python include decimal characters (such as 0, 1, 2..), digits (such as subscript, superscript), and characters with the Unicode numeric value property (such as fractions, roman numerals, currency numerators).<\/p>\n Syntax:<\/strong><\/p>\n Parameters: <\/strong>This function has no parameters.<\/p>\n Return Value:<\/strong><\/p>\n The isnumeric() method gives:<\/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 Go through our tutorial and learn about various Python String Method Examples<\/a> and learn how to apply the knowledge while dealing with strings.<\/p>\n In the previous article, we have discussed Python Program for help() Function with Examples isnumeric() Method in Python: If all of the characters are numeric (0-9), the isnumeric() method returns True; otherwise, it returns False. Exponents such as \u00b2 and \u00be are also considered numeric values. Because all of the characters in the string must …<\/p>\n
\nisnumeric() Method in Python:<\/strong><\/p>\nstring.isnumeric()<\/pre>\n
\n
Given string = '-6'\r\nGiven string = '5\/6'\r\nGiven string = 'btechgeeks 12345'<\/pre>\n
The given string = -6\r\nChecking if the given string has all numeric characters or not = False\r\nThe given string = 5\/6\r\nChecking if the given string has all numeric characters or not = False\r\nThe given string = btechgeeks 12345\r\nChecking if the given string has all numeric characters or not = False<\/pre>\n
Given string = '\\u0030'\r\nGiven string = '1.7'\r\nGiven string = '\\u00B2'<\/pre>\n
The given string = 0\r\nChecking if the given string has all numeric characters or not = True\r\nThe given string = 1.7\r\nChecking if the given string has all numeric characters or not = False\r\nThe given string = \u00b2\r\nChecking if the given string has all numeric characters or not = True<\/pre>\n
String isnumeric() Method Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Give the string as static input and store it in a variable.\r\n# unicode for the number 0\r\ngvn_strng1 = '\\u0030'\r\n# Apply isnumeric() function to the given string in which If all of the\r\n# characters are numeric (0-9), the isnumeric() method returns True;\r\n# otherwise, it returns False.\r\n# Store it in another variable.\r\nrslt_1 = gvn_strng1.isnumeric()\r\n# Print the above-given String.\r\nprint(\"The given string = \", gvn_strng1)\r\n# Print the result after checking if the given string has all numeric\r\n# characters or not.\r\nprint(\"Checking if the given string has all numeric characters or not = \", rslt_1)\r\n# Similarly, do the same for other strings and print the result.\r\ngvn_strng2 = '1.7'\r\nrslt_2 = gvn_strng2.isnumeric()\r\nprint(\"The given string = \", gvn_strng2)\r\nprint(\"Checking if the given string has all numeric characters or not = \", rslt_2)\r\n# unicode for the value \u00b2\r\ngvn_strng3 = '\\u00B2'\r\nrslt_3 = gvn_strng3.isnumeric()\r\nprint(\"The given string = \", gvn_strng3)\r\nprint(\"Checking if the given string has all numeric characters or not = \", rslt_3)\r\n<\/pre>\n
The given string = 0\r\nChecking if the given string has all numeric characters or not = True\r\nThe given string = 1.7\r\nChecking if the given string has all numeric characters or not = False\r\nThe given string = \u00b2\r\nChecking if the given string has all numeric characters or not = True<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Give the string as user input using the input() function and store it in a variable.\r\ngvn_strng1 = input(\"Enter some Random String = \")\r\n# Apply isnumeric() function to the given string in which If all of the\r\n# characters are numeric (0-9), the isnumeric() method returns True;\r\n# otherwise, it returns False.\r\n# Store it in another variable.\r\nrslt_1 = gvn_strng1.isnumeric()\r\n# Print the above-given String.\r\nprint(\"The given string = \", gvn_strng1)\r\n# Print the result after checking if the given string has all numeric\r\n# characters or not.\r\nprint(\"Checking if the given string has all numeric characters or not = \", rslt_1)\r\n# Similarly, do the same for other strings and print the result.\r\ngvn_strng2 = input(\"Enter some Random String = \")\r\nrslt_2 = gvn_strng2.isnumeric()\r\nprint(\"The given string = \", gvn_strng2)\r\nprint(\"Checking if the given string has all numeric characters or not = \", rslt_2)\r\ngvn_strng3 = input(\"Enter some Random String = \")\r\nrslt_3 = gvn_strng3.isnumeric()\r\nprint(\"The given string = \", gvn_strng3)\r\nprint(\"Checking if the given string has all numeric characters or not = \", rslt_3)\r\n<\/pre>\n
Enter some Random String = -10.5\r\nThe given string = -10.5\r\nChecking if the given string has all numeric characters or not = False\r\nEnter some Random String = 5\/6\r\nThe given string = 5\/6\r\nChecking if the given string has all numeric characters or not = False\r\nEnter some Random String = btechgeeks 12345\r\nThe given string = btechgeeks 12345\r\nChecking if the given string has all numeric characters or not = False<\/pre>\n
\n