Cheap Jerseys Cheap NFL Jerseys Cheap NFL Jerseys Cheap Football jerseys Cheap NFL Jerseys Wholesale Jerseys Cheap NHL Jerseys Cheap Jerseys From China Cheap MLB Jerseys Cheap Jerseys Cheap Jerseys Cheap Jerseys Wholesale Jerseys Python String swapcase() Method - WTMatter

Python String swapcase() Method

Python String Swapcase() Method

This is a tutorial of the Python String swapcase() method. Learn to convert lowercase into uppercase & uppercase into lowercase in a given string.

Python String swapcase()

The Python str.swapcase() method converts all of the uppercase alphabets into lowercase and all of the lowercase alphabets into uppercase in a given string and returns it as a new string.

Note. The original string on which this method is applied remains unchanged.

To convert a given string into either case, i.e. into lowercase or uppercase only, you can use the Python String methods str.lower() and str.upper() respectively.

Syntax

Given below is the syntax of the Python String swapcase() method.

swapcase() Parameters

This method does not take any arguments as it only checks the given string on which it is applied, so no additional data is required in the form of arguments.

swapcase() Return Value

It returns the string created from the given String such that in the returned string, the cases of the alphabets are swapped. In other words, in the returned string all of the alphabets that were originally in lowercase in the given string are now in uppercase and similarly, the alphabets that were originally in uppercase in the given string are now in lowercase.

Example: Swapping Case using Python String swapcase() method

The following example demonstrates the usage of the Python String swapcase() method.

#UPPERCASE String
welcome = "WELCOME TO WTMATTER.COM"
print(welcome.swapcase())

#lowercase String
welcome = "welcome to wtmatter.com"
print(welcome.swapcase())

#AlTeRnAtE CaSe
welcome = "WeLcOmE To wTmAtTeR.CoM"
print(welcome.swapcase())

Output.

welcome to wtmatter.com
WELCOME TO WTMATTER.COM
wElCoMe tO WtMaTtEr.cOm

As you can observe in the output, the string in UPPERCASE is converted into lowercase and the string in lowercase is converted into uppercase. In the alternate case string also, the lowercase alphabets are converted into uppercase and the uppercase alphabets are converted into lowercase.

Related. Case Converted by WTMatter (Online Tool)

I hope you found this guide useful. If so, do share it with others who are willing to learn Python and other programming languages. If you have any questions related to this article, feel free to ask us in the comments section.

And do not forget to subscribe to WTMatter!

Subscribe To WTMatter!

Receive updates of our latest articles via email. Enter your email address below to get started.

Leave a Reply

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