Table of Contents
The string swapcase() method converts all uppercase characters to lowercase and all lowercase characters to uppercase characters of the given string, and returns it.
The format of swapcase() method is:
string.swapcase()
Note: Not necessarily, string.swapcase().swapcase() == string
1. String swapcase() Parameters()
swapcase() method doesn’t take any parameters.
2. Return value from String swapcase()
swapcase() method returns the string where all uppercase characters are converted to lowercase, and lowercase characters are converted to uppercase.
3. Example 1: Swap lowercase to uppercase and vice versa using swapcase()
# example string string = "THIS SHOULD ALL BE LOWERCASE." print(string.swapcase()) string = "this should all be uppercase." print(string.swapcase()) string = "ThIs ShOuLd Be MiXeD cAsEd." print(string.swapcase())
Output
this should all be lowercase. THIS SHOULD ALL BE UPPERCASE. tHiS sHoUlD bE mIxEd CaSeD.
Note: If you want to convert string to lowercase only, use lower(). Likewise, if you want to convert string to uppercase only, use upper().
Related posts:
Python String strip()
Python Program to Find Factorial of Number Using Recursion
Python Multiple Inheritance
Python List
Python String casefold()
Python pow()
Python Set add()
Java InputStream to String
Python String title()
Python delattr()
Python Program to Create a Long Multiline String
Python Machine Learning Eqution Reference - Sebastian Raschka
Python help()
Python List insert()
Python Program to Check the File Size
Python Set discard()
Python Set symmetric_difference()
Python max()
Python Set difference()
Python Program to Multiply Two Matrices
Python Program to Differentiate Between type() and isinstance()
Python List copy()
Python sum()
Python eval()
Python Program to Convert Kilometers to Miles
Python Program to Remove Punctuations From a String
Python int()
Check If a String Is Numeric in Java
Python String split()
Python Program to Check Leap Year
Python object()
Python Decorators