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 Exception Handling Using try, except and finally statement
Python Program to Check if a Key is Already Present in a Dictionary
Python format()
Python Program to Display the multiplication Table
Python Multiple Inheritance
Python Program to Multiply Two Matrices
Python Decorators
Python exec()
Python Program to Check the File Size
Python List reverse()
Python String lstrip()
Introduction to Scientific Programming with Python - Joakim Sundnes
Python String isalnum()
Python round()
Convert String to int or Integer in Java
Python String translate()
Python Iterators
Python Program to Sort a Dictionary by Value
Python Package
Python Program to Add Two Numbers
Python Program to Merge Two Dictionaries
Machine Learning with Python for everyone - Mark E.Fenner
String Initialization in Java
Python help()
Python Program to Convert Bytes to a String
Python max()
Python input()
Python list()
Python String rsplit()
Python Set symmetric_difference()
Python sorted()
Python strftime()