Python String – swapcase() method

It is a method in python that swaps the cases of all the alphabets i.e. concerts all the upper case characters to lower case and all the lower case characters to upper case.

Syntax:
string.swapcase()

Example 1:

s = “CODE, hustle
x = s.swapcase()
print(x)

Output:

code, HUSTLE

Explanation:

Here “CODE” is converted to “code” (Upper case to lower case) and “hustle” is converted to “HUSTLE” (lower case to upper case).

Example 2:

s = “CODEwindow is a tech PLATFORM
x = s.swapcase()
print(x)

Output:

codeWINDOW IS A TECH platform

Explanation:

Here all the upper case characters i.e. “CODE” and “PLATFORM” are converted to lower case characters (“code”, “platform”) and all the lower case characters i.e. “window is a tech” are converted to upper case character (“WINDOW IS A TECH”).

You Missed