For this method, no external module needs to import. Wherever you want to modify a string’s character cases, call it. Let’s have a look at the swapcase() definition:
The Python String swapcase() function transforms the case of uppercase string characters to lowercase and vice versa. There is no parameter needed, and a string returns after case conversion.
The syntax of the method is: str.swapcase();
Key Points :
• Return Type: String.
• Parametric values: No parameters are taken into the swapcase() function.
• The swapcase() returns the string of which all uppercase characters are translated into the lowercase, and lowercase characters are translated into uppercase.
• Suppose a string is a=”ABC” is given, and if the swapcase() method is applied to it, it will be abc.
Below is the python program to demonstrate the swapcase() function:
str = "The Best Learning Resource for Online Education"; print (str.swapcase()) str = "THE BEST LEARNING RESOURCE FOR ONLINE EDUCATION"; print (str.swapcase())
When we run above the program, the outcome is as follows:
tHE bEST lEARNING rESOURCE FOR oNLINE eDUCATION
the best learning resource for online education
Below are several other functions that we can use to work with string in Python 3