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 eval()
Python Program to Check if a Number is Odd or Even
Python List extend()
Python __import__()
Python min()
Python Program to Add Two Matrices
Java – String to Reader
Python Program to Display Calendar
Python Deep Learning Cookbook - Indra den Bakker
Python delattr()
Python Objects and Classes
Python Program to Find Factorial of Number Using Recursion
Why String is Immutable in Java?
Python Program to Trim Whitespace From a String
Python String index()
Python super()
Python String center()
Python *args and **kwargs
Python String zfill()
Python divmod()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python for Loop
Python Program to Find LCM
Python type()
Python Strings
Python Global Keyword
Python String isprintable()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python List remove()
Python Program to Swap Two Variables
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Set symmetric_difference()