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 String maketrans()
Python Set issubset()
Python Program to Count the Occurrence of an Item in a List
Python String rstrip()
Python Dictionary keys()
Python input()
Python Program to Swap Two Variables
Python Program to Represent enum
Java String to InputStream
Python repr()
Python Strings
Python pass statement
Python memoryview()
Python next()
Generate a String
Python List remove()
Python sum()
Python String rsplit()
Python Sets
Python String index()
Python String format_map()
Python Dictionary items()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Program to Find the Square Root
Python List extend()
Python Namespace and Scope
Python object()
Python strptime()
String Processing with Apache Commons Lang 3
Python Matrices and NumPy Arrays
Python print()
Python Program to Check if a Key is Already Present in a Dictionary