Python String swapcase()

Python string swapcase() method is a built-in function that converts all uppercase characters into lowercase and all lowercase characters into uppercase characters of a given string and returns a new string.

swapcase() Syntax

The Syntax of swapcase() method is:


swapcase() Parameters

The swapcase() method doesn’t take any parameters.

swapcase() Return Value

The swapcase() method returns a copy of the string where all the uppercase characters are converted into lowercase characters and vice-versa.

In case the string has other than alphabets those characters will not be converted and returned as-is.

Example: Python Program to change the case of a given string

text1 = "pYTHON tUTORIALS"

text2 = "HELLO WORLD"

text3 = "welcome to itsmycode"

text4 ="12345!!!"


Python Tutorials
hello world
Note: If you want to convert given string into lowercase only it is recommended to use lower() method. Likewise, if you want to convert given string into uppercase only it is recommended to use upper() method.
Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like