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.

The method does not change the original string.

Syntax

string.swapcase()

Examples

Example: Swap case of all characters in a string

S = 'Hello, World!'
x = S.swapcase()
print(x)	# hELLO, wORLD!

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

Example:

S = '123 abc $@%'
x = S.swapcase()
print(x)	# 123 ABC $@%