all Python 3Strings (str)function
str.swapcase
case
Return a copy with uppercase characters converted to lowercase and vice versa.
Syntax
s.swapcase()
Applying swapcase() twice does not necessarily restore the original: ß turns into SS, and back again it becomes ss. Characters without case — digits, spaces, punctuation — are left alone, and outside of exercises this method is rarely what a real task needs.
Examples
print('Hello World'.swapcase()) # → hELLO wORLD
print('Привет'.swapcase()) # → пРИВЕТ
print('abcABC123'.swapcase()) # → ABCabc123
See also
Open in the full glossarydocs.python.orgReport an inaccuracy