{"id":24464,"date":"2021-10-17T18:41:41","date_gmt":"2021-10-17T13:11:41","guid":{"rendered":"https:\/\/python-programs.com\/?p=24464"},"modified":"2021-11-05T19:24:10","modified_gmt":"2021-11-05T13:54:10","slug":"program-for-python-string-isalnum-method","status":"publish","type":"post","link":"https:\/\/python-programs.com\/program-for-python-string-isalnum-method\/","title":{"rendered":"Program for Python String isalnum() Method"},"content":{"rendered":"
In the previous article, we have discussed Python Program for center() Function<\/a> The isalnum() method returns a value True if all of the characters are alphanumeric, which means they are alphabet letters (a-z) and numbers (0-9).<\/p>\n (space)!#%&? etc are examples of characters that are not alphanumeric.<\/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 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 center() Function isalnum() Function in Python: The isalnum() method returns a value True if all of the characters are alphanumeric, which means they are alphabet letters (a-z) and numbers (0-9). (space)!#%&? etc are examples of characters that are not alphanumeric. Syntax: string.isalnum() Parameters: This function …<\/p>\n
\nisalnum() Function in Python:<\/strong><\/p>\nstring.isalnum()<\/pre>\n
Given first string = \"pythonprograms\"\r\nGiven second string = \"10345 @@@good morning\"<\/pre>\n
The above given first string is : pythonprograms\r\nThe given first string after applying isalnum() function: True\r\nThe above given second string is : 10345 @@@good morning\r\nThe given second string after applying isalnum() function: False<\/pre>\n
Given first string = \"hello this is python programming platform\"\r\nGiven second string = \"hello123\"<\/pre>\n
The above given first string is : hello this is python programming platform\r\nThe given first string after applying isalnum() function: False\r\nThe above given second string is : hello123\r\nThe given second string after applying isalnum() function: True<\/pre>\n
Program for isalnum() 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 = \"pythonprograms\"\r\n# Apply isalnum() function to the given first string that returns a value\r\n# True if all of the characters are alphanumeric, which means they are alphabet\r\n# letters (a-z) and numbers (0-9).\r\n# Store it in another variable.\r\nrslt_str1 = gvn_fststr.isalnum()\r\n# Print the above given String\r\nprint(\"The above given first string is :\", gvn_fststr)\r\n# Print the above given String after applying isalnum() function.\r\nprint(\"The given first string after applying isalnum() function:\", rslt_str1)\r\n# Similarly do the same for other string and print the result string.\r\ngvn_scndstr = \"10345 @@@good morning\"\r\nrslt_str2 = gvn_scndstr.isalnum()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying isalnum() function:\", rslt_str2)\r\n<\/pre>\n
The above given first string is : pythonprograms\r\nThe given first string after applying isalnum() function: True\r\nThe above given second string is : 10345 @@@good morning\r\nThe given second string after applying isalnum() function: False<\/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 isalnum() function to the given first string that returns a value\r\n# True if all of the characters are alphanumeric, which means they are alphabet\r\n# letters (a-z) and numbers (0-9).\r\n# Store it in another variable.\r\nrslt_str1 = gvn_fststr.isalnum()\r\n# Print the above given String\r\nprint(\"The above given first string is :\", gvn_fststr)\r\n# Print the above given String after applying isalnum() function.\r\nprint(\"The given first string after applying isalnum() 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.isalnum()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying isalnum() function:\", rslt_str2)\r\n<\/pre>\n
Enter some Random String = hello this is python programming platform\r\nThe above given first string is : hello this is python programming platform\r\nThe given first string after applying isalnum() function: False\r\nEnter some Random String = hello123\r\nThe above given second string is : hello123\r\nThe given second string after applying isalnum() function: True<\/pre>\n
\n