The swapcase() method in Python string is supposed to return a copy of the string where all the case-based characters got their case swapped. The string swapcase() method in Python Programming converts all the uppercase characters to lowercase of the given string and vice versa and also returns the same.
Here is the syntax for swapcase() method:
str.swapcase();
This method in Python String returns a copy of the string where all the case-based characters have had all their case swapped.
The example below shows the usage of swapcase() method.
#!/usr/bin/python str = "this is string example....wow!!!"; print str.swapcase() str = "THIS IS STRING EXAMPLE....WOW!!!"; print str.swapcase()
When the above program is run, it produces the following result:
THIS IS STRING EXAMPLE....WOW!!! this is string example....wow!!!
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.