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

Basic useTry it yourself
print("Hello World".swapcase())

Output

hELLO wORLD
Not always reversibleTry it yourself
print("ß".swapcase(), "ß".swapcase().swapcase())  # not always reversible

Output

SS ss

Version history

VersionChange
Python 3.0Added