The swapcase Method in Python: Inverting Character Case in a String
The swapcase method returns a copy of the string with each letter’s case inverted. Lowercase letters become uppercase, and uppercase letters become lowercase.
swapcase()
'Cat TrIckster!'.swapcase() # cAT tRiCKSTER!
For 8-bit Unicode strings, the method’s result can vary based on the locale. Therefore, the following expression is not always true:
if "string".swapcase().swapcase() == "string": ...