Python String swapcase() Method

Swaps case of all characters in a string

Usage

The swapcase() method returns a copy of the string with uppercase characters converted to lowercase and vice versa. This method does not change the original string.

Syntax

string.swapcase()

Examples

# Swap case of all characters in a string
S = 'Hello, World!'
x = S.swapcase()
print(x)
# Prints hELLO, wORLD!

swapcase() method ignores numbers and special characters in a string.

S = '123 abc [email protected]%'
x = S.swapcase()
print(x)
# Prints 123 ABC [email protected]%