str.swapcase() Swap case
Last updated: 2026-09-22
str.swapcase() Swap case
str.swapcase() swaps the case of every letter.
| Category | String Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
str.swapcase()
Returns:str. A copy with uppercase and lowercase letters swapped.
Mutates the original:No (returns a new object)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
hELLO wORLD
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat does swapcase() do?
AIt converts uppercase to lowercase and lowercase to uppercase. 'Hello World'.swapcase() gives 'hELLO wORLD'.
QWhat happens to Chinese characters and digits?
AThey are preserved unchanged, because they have no case.
QAre there any pitfalls to watch out for?
AFor certain Unicode characters the result may be non-intuitive (a few characters change length when converted). For ordinary business use, lower()/upper() are more common.