Python Tutorial Python Advanced Python References Python Libraries

Python String - swapcase() Method



The Python 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 example below, 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