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 sorted()
Python Set issuperset()
Python String find()
Python Program to Check If Two Strings are Anagram
Java – Reader to String
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Program to Check Armstrong Number
Python String rindex()
Python String istitle()
Python Function Arguments
Python divmod()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python chr()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python float()
Python String startswith()
Python map()
Python Program to Find the Largest Among Three Numbers
Python Program to Trim Whitespace From a String
Python set()
Python Dictionary clear()
Python File I/O Operation
Python int()
Python Program to Print Output Without a Newline
Python Program to Extract Extension From the File Name
Python String upper()
Python bytearray()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Set copy()
Python String rstrip()
Python help()
Python open()