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 Dictionary setdefault()
Python Program to Differentiate Between type() and isinstance()
Python help()
Python Shallow Copy and Deep Copy
Python Program to Check Whether a String is Palindrome or Not
Python Program to Sort a Dictionary by Value
Python Modules
Python String translate()
Python Program to Check if a Number is Positive, Negative or 0
Python Program to Display the multiplication Table
Python time Module
Python timestamp to datetime and vice-versa
Python Program to Represent enum
Python String startswith()
Python bytes()
Python Program to Generate a Random Number
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python divmod()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Find the Sum of Natural Numbers
Python Dictionary update()
Python tuple()
Python Program to Find Numbers Divisible by Another Number
Java InputStream to String
Python Program to Merge Mails
Python Program to Copy a File
Python del Statement
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Capitalize the First Character of a String
Python *args and **kwargs
Deep Learning with Python - Francois Chollet
Python round()