In python, the string swapcase() method is useful to convert the given string lowercase characters to uppercase and uppercase characters to lowercase.
Following is the pictorial representation of the string swapcase()
method functionality in python.
If you observe the above diagram, we are trying to convert the given string “Hi GUEST Hi
” lowercase characters to uppercase and uppercase characters to lowercase using the swapcase
function in python.
Following is the syntax of defining a string swapcase method in python.
The python swapcase() method will not accept any parameters.
Following is the example of converting the given string lowercase characters to uppercase and uppercase characters to lowercase using the string swapcase()
method in python.
If you observe the above example, we are converting the given string lowercase characters to uppercase and uppercase characters to lowercase using the swapcase()
method.
When you execute the above python program, you will get the result as shown below.
This is how you can use the string swapcase() method in python to swap the given string characters based on your requirements.