English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The swapcase() method of the string converts all uppercase characters in the given string to lowercase and all lowercase characters to uppercase, and then returns the converted string.
The format of the swapcase() method is:
string.swapcase()
Note:It may not be string.swapcase().swapcase() == string
The swapcase() method does not take any parameters.
The swapcase() method returns a string in which all uppercase characters are converted to lowercase, and all lowercase characters are converted to uppercase.
# String example 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())
When running the program, the output is:
this should all be lowercase. THIS SHOULD ALL BE UPPERCASE. tHiS sHoUlD bE mIxEd CaSeD.
Note:If you only want to convert a string to lowercase, please uselower(). Similarly, if you want to convert a string to uppercase only, please useupper().