In this article, you will learn about the Python string swapcase() method to swap the lower case to uppercase and vice versa. swapcase in python method is used when you want to work with string in python.
In the previous tutorial, we have seen Python string startswith function to check whether a string with specified prefix or not.
Headings of Contents
Python swapcase() string method
Python swapcase() string method is used to convert lowercase to uppercase and uppercase to lowercase. It does not require any parameter and return a new string after conversion.
Syntax
The syntax of string swapcase function in Python.
string.swapcase()
Return Value
The swapcase function in Python return new string.
Python string swapcase example:
Here we will take some example to understand python string swapcase method
Example 1:
a = 'PROGRAMMING'
result = a.swapcase()
print(result)
Example 2:
a = 'Programming'
result = a.swapcase()
print(result)
Example 3:
a = ['Programming', 'FUNDA', 'is', 'a', 'educational', 'site']
result = []
for i in a:
result.append(i.swapcase())
print(result)
Output
['pROGRAMMING', 'funda', 'IS', 'A', 'EDUCATIONAL', 'SITE']
Conclusion
In this tutorial, You have learned the Python string swapcase method to swap the uppercase to lowercase and vice versa. swapcase in python is the best string function to convert uppercase to lowercase and lowercase to uppercase at the same time.
I hope this tutorial will help you. if you like this article, please share it with your friends who want to learn Python programming.
Other string methods
- String endswith() method
- String casefold() method
- String center() method
- String capitalize() method
- String count() method
- String index() method
- String format() method
- String isalpha() method
- String isidentifier() method
- String islower() method
- String isupper() method
For More Information:- Click Here