swapcase() method of str class

swapcase() converts all the lower case characters of the string object into lower case and all the upper case characters into lower case

Str Updated 15 Mar 2017 1 min read

Method Name

swapcase

Method Signature

swapcase()

Method Overview

  • The method swapcase() converts all the lowercase characters of the string object into upper case and all the uppercase characters the string object into lower case and returns a new string object.

Example

python
sampleString    = "That is only the box. The sheep you asked for is inside"

caseSwapped     = sampleString.swapcase()

print("Before case swap :%s"%(sampleString))

print("After case swap :%s"%(caseSwapped))

Output

Output
Before case swap :That is only the box. The sheep you asked for is inside

After case swap :tHAT IS ONLY THE BOX. tHE SHEEP YOU ASKED FOR IS INSIDE