Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python String swapcase() method is used to convert all lowercase characters of the string into uppercase and all uppercase characters of the string into lowercase. Any symbol, space, special character or number in the string is ignored while applying this method. Only Alphabets are converted.

Syntax

string.swapcase()

Parameters

No parameter is required.

Return Value

Returns the string with all lowercase characters of the string into uppercase and all uppercase characters of the string into lowercase.

Example:

In the below example, swapcase() method is used to convert all lowercase characters of the string into uppercase and all uppercase characters of the string into lowercase.

MyString = "Hello John!"
print(MyString.swapcase())

The output of the above code will be:

hELLO jOHN!

❮ Python String Methods