Tutorial Study Image

Python swapcase()

The swapcase() function in python helps to return a copy of the original string in which all the uppercase characters of the string are converted into lowercase also all the lowercase characters of the string are converted into uppercase.


string.swapcase() 
 

swapcase() Parameters:

The swapcase() method doesn't take any parameters. If we call this function all the cases (Upper& Lower) will be reversed.

swapcase() Return Value

The return value is always a string. At the time of conversion, all symbols and letters are ignored.

Input Return Value
string upper & lower converted string

Examples of swapcase() method in Python

Example 1: How to convert a string to lowercase & uppercase using swapcase()?


# example string
string1 = "CONVERTING INTO LOWERCASE."
print(string1.swapcase())

string2 = "converting into uppercase."
print(string2.swapcase())

string3 = "String Have Both Upper And Lowercase."
print(string3.swapcase())
 

Output:


converting into lowercase.
CONVERTING INTO UPPERCASE.
sTRING hAVE bOTH uPPER aND lOWERCASE.

Example 2: How swapcase() is used in Python?


string = "HI HOW ARE YOU?"
print(string.swapcase())


string = " I am fine."
print(string.uppercase())
 

Output:


hi how are you?
IAM FINE.