In this section, we will learn what String swapcase() method is and how to use it in Python.
How to change from lowercase to uppercase? (swapcase() Method)
The Python string swapcase() method is used to turn those characters of a string that are lowercase into uppercase and vice versa.
Note: this method does not change the original content of the target string. Instead, it will return a new one as a result.
Python String swapcase() Method Syntax:
string.swapcase()
String swapcase() Method Parameter
The method does not take an argument.
String swapcase() Method Return Value
The return value of this method is a new string that contains a copy of the target string (the one that invoked this method) where lowercase letters are converted into uppercase and vice versa.
Example: using python string swapcase() method
s1 = "My name is John Doe" print(s1.swapcase())
Output:
mY NAME IS jOHN dOE