Python String swapcase()

Python String.swapcase() is used to swap the case of characters in given string. Lowercase characters are converted to uppercase, and the uppercase characters are converted to lowercase. swapcase() method returns a new resulting string after swapping cases, and the original string remains unchanged.

In this tutorial, we will learn the syntax and examples for swapcase() method of String class.


The syntax to call swapcase() method on string x in Python is



In the following program, we take a string 'Hello World', and swap the cases of the characters in this string using swapcase() method.

x = 'Hello World'
result = x.swapcase()
print('Original String  : ', x)
print('Result String    : ', result)
Try Online


Original String  :  Hello World
Result String    :  hELLO wORLD


In this Python Tutorial, we learned how to swap the cases of characters in a String using swapcase() method, with examples.