Python Tutorial Python Advanced Python Resources Python Libraries
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Python - String swapcase() Method



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 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

5