{"id":24542,"date":"2021-10-22T10:00:36","date_gmt":"2021-10-22T04:30:36","guid":{"rendered":"https:\/\/python-programs.com\/?p=24542"},"modified":"2021-11-05T19:06:13","modified_gmt":"2021-11-05T13:36:13","slug":"program-for-python-string-swapcase-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/program-for-python-string-swapcase-function\/","title":{"rendered":"Program for Python String swapcase() Function"},"content":{"rendered":"
In the previous article, we have discussed Program for Python String title() Function<\/a> The swapcase() method returns a string in which all upper case letters are converted to lower case and vice versa.<\/p>\n Syntax:<\/strong><\/p>\n Parameters:<\/strong> This function doesn’t have any 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 Program for Python String title() Function Python String swapcase() Function: The swapcase() method returns a string in which all upper case letters are converted to lower case and vice versa. Syntax: string.swapcase() Parameters: This function doesn’t have any parameters. Examples: Example1: Input: Given first string = “welcome to …<\/p>\n
\nPython String swapcase() Function:<\/strong><\/p>\nstring.swapcase()<\/pre>\n
Given first string = \"welcome to PYTHON-Programs\"\r\nGiven second string = \"HELLO ALL GOOD MORNING\"<\/pre>\n
The above given first string is : welcome to PYTHON-Programs\r\nThe given first string after applying swapcase() function:\r\nWELCOME TO python-pROGRAMS\r\nThe above given second string is : HELLO ALL GOOD MORNING\r\nThe given second string after applying swapcase() function:\r\nhello all good morning<\/pre>\n
Given first string = \"hello ALL gOOD MORNing\"\r\nGiven second string = \"HELLO this is BTECHGEEKS\"<\/pre>\n
The above given first string is : hello ALL gOOD MORNing\r\nThe given first string after applying swapcase() function:\r\nHELLO all Good mornING\r\nThe above given second string is : HELLO this is BTECHGEEKS\r\nThe given second string after applying swapcase() function:\r\nhello THIS IS btechgeeks<\/pre>\n
Program for String swapcase() 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 = \"welcome to PYTHON-Programs\"\r\n# Apply swapcase() function to the given first string that returns a string\r\n# in which all upper case letters are converted to lower case and vice versa.\r\n# Store it in another variable.\r\nrslt_str1 = gvn_fststr.swapcase()\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 swapcase() function.\r\nprint(\"The given first string after applying swapcase() function:\")\r\nprint(rslt_str1)\r\n# Similarly do the same for other string and print the result string.\r\ngvn_scndstr = \"HELLO ALL GOOD MORNING\"\r\nrslt_str2 = gvn_scndstr.swapcase()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying swapcase() function:\")\r\nprint(rslt_str2)\r\n<\/pre>\n
The above given first string is : welcome to PYTHON-Programs\r\nThe given first string after applying swapcase() function:\r\nWELCOME TO python-pROGRAMS\r\nThe above given second string is : HELLO ALL GOOD MORNING\r\nThe given second string after applying swapcase() function:\r\nhello all good morning<\/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 swapcase() function to the given first string that returns a string\r\n# in which all upper case letters are converted to lower case and vice versa.\r\n# Store it in another variable.\r\nrslt_str1 = gvn_fststr.swapcase()\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 swapcase() function.\r\nprint(\"The given first string after applying swapcase() function:\")\r\nprint(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.swapcase()\r\nprint(\"The above given second string is :\", gvn_scndstr)\r\nprint(\"The given second string after applying swapcase() function:\")\r\nprint(rslt_str2)\r\n<\/pre>\n
Enter some Random String = hello ALL gOOD MORNing\r\nThe above given first string is : hello ALL gOOD MORNing\r\nThe given first string after applying swapcase() function:\r\nHELLO all Good mornING\r\nEnter some Random String = HELLO this is BTECHGEEKS\r\nThe above given second string is : HELLO this is BTECHGEEKS\r\nThe given second string after applying swapcase() function:\r\nhello THIS IS btechgeeks<\/pre>\n
\n