{"id":16495,"date":"2021-08-12T09:33:18","date_gmt":"2021-08-12T04:03:18","guid":{"rendered":"https:\/\/python-programs.com\/?p=16495"},"modified":"2021-11-22T18:38:30","modified_gmt":"2021-11-22T13:08:30","slug":"python-program-to-check-if-all-characters-of-string-are-alphanumeric-or-not","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-check-if-all-characters-of-string-are-alphanumeric-or-not\/","title":{"rendered":"Python Program to Check if all Characters of String are Alphanumeric or Not"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Calculate EMI<\/a><\/p>\n The isalnum() Method is a String Class pre-defined method that can be used on any String Object. It returns Boolean Values based on the following criteria.<\/p>\n For Example:<\/strong><\/p>\n Given string = “Hellobtechgeeks123”<\/p>\n Output: returns true since all the characters are alphabets and numbers.<\/p>\n Given string = “good morning@ #btechgeeks12345”<\/p>\n Output: returns False since all the given String contains some special symbols like #,@, and spaces.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example 2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to Check if all Characters of String are Alphanumeric or Not.<\/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 Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Calculate EMI isalnum() Method: The isalnum() Method is a String Class pre-defined method that can be used on any String Object. It returns Boolean Values based on the following criteria. If all of the characters in the given string are Alphanumerical, it returns True. If …<\/p>\nisalnum() Method:<\/h4>\n
\n
Given string = \"Hellobtechgeeks123\"<\/pre>\n
The Given string { Hellobtechgeeks123 } is Alpha Numeric<\/pre>\n
Given string = \"good morning@ #btechgeeks12345\"<\/pre>\n
The Given string { good morning@ #btechgeeks12345 } is not Alpha Numeric<\/pre>\n
Program to Check if all Characters of String are Alphanumeric or Not<\/h2>\n
\n
Method #1: Using isalnum() Method (Static input)<\/h3>\n
\n
# Give the string as static input and store it in a variable.\r\ngvn_strng = \"Hellobtechgeeks123\"\r\n# Check whether the Given string is alphanumeric using built-in alnum() method\r\n# and store it in another variable.\r\nBol_val = gvn_strng.isalnum()\r\n# Check whether the above result is True or not using the if conditional statement.\r\nif(Bol_val == True):\r\n # If it is True, Print the given string is\u00a0 alphanumeric.\r\n print(\"The Given string {\", gvn_strng, \"} is Alpha Numeric\")\r\nelse:\r\n # If it is False, Print the given string is not alphanumeric.\r\n print(\"The Given string {\", gvn_strng, \"} is not Alpha Numeric\")\r\n<\/pre>\n
The Given string { Hellobtechgeeks123 } is Alpha Numeric<\/pre>\n
Method #2: Using isalnum() Method (User input)<\/h3>\n
\n
# Give the string as user input using the input()function and store it in a variable.\r\ngvn_strng = input('Enter some random string = ')\r\n# Check whether the Given string is alphanumeric using built-in alnum() method\r\n# and store it in another variable.\r\nBol_val = gvn_strng.isalnum()\r\n# Check whether the above result is True or not using the if conditional statement.\r\nif(Bol_val == True):\r\n # If it is True, Print the given string is\u00a0 alphanumeric.\r\n print(\"The Given string {\", gvn_strng, \"} is Alpha Numeric\")\r\nelse:\r\n # If it is False, Print the given string is not alphanumeric.\r\n print(\"The Given string {\", gvn_strng, \"} is not Alpha Numeric\")\r\n\r\n<\/pre>\n
Enter some random string = good morning @btechgeeks #123456\r\nThe Given string { good morning @btechgeeks #123456 } is not Alpha Numeric<\/pre>\n
\n