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 sum()
Python String find()
Python String isupper()
Python String maketrans()
Python max()
Python Program to Illustrate Different Set Operations
Python iter()
Python Set difference_update()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python List copy()
Python Program to Find Armstrong Number in an Interval
Python Set union()
Python Program to Convert Two Lists Into a Dictionary
Python Program to Check Whether a String is Palindrome or Not
Python String isdecimal()
Python Program to Randomly Select an Element From the List
Jackson – Marshall String to JsonNode
Python Program to Check if a Number is Positive, Negative or 0
Converting a Stack Trace to a String in Java
Python format()
Python *args and **kwargs
Python hex()
Python Program to Shuffle Deck of Cards
Python exec()
Python Program to Iterate Over Dictionaries Using for Loop
Python List index()
Map to String Conversion in Java
Convert Character Array to String in Java
Python vars()
String Set Queries
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python frozenset()