Python 3 reference · String Methods
Python String swapcase() Method
Return a copy with upper-case letters converted to lower case and vice versa.
Python 3 Since 3.0
Syntax
str.swapcase()
Return value
A new string.
Examples
print("Hello World".swapcase())
Output
hELLO wORLD
print("ß".swapcase(), "ß".swapcase().swapcase()) # not always reversible
Output
SS ss
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
str.upper()· Return a copy of the string with all cased characters converted to upper case.str.lower()· Return a copy of the string with all cased characters converted to lower case.- Python Strings · tutorial