Python String swapcase() Method

In this tutorial, We will see the python string swapcase() method with examples.

swapcase() Method

The swapcase() method is one of the methods in a python string. The swapcase() method is used for string conversion.

swapcase() method converts uppercase characters to lowercase characters and likewise converts lowercase characters to uppercase characters.

Syntax of Python string swapcase() method

This is the syntax of the python string swapcase() method.

string.swapcase()
Example of Python string swapcase() method
#Example 1 

text = "PYTHON IS A PROGRAMMING LANGUAGE"

print(text.swapcase())
#output : python is a programming language
#Example 2

text = "python swapcase() method"
print(text.swapcase())

#output: PYTHON SWAPCASE() METHOD

#Exmaple 3

message = "hello WORLD!"
msg = message.swapcase()
print(msg)

#output: 'HELLO world!'

Program: Take a string from the user and convert the uppercase characters to lowercase characters and lowercase characters to uppercase characters.

message = input("Enter the message")
msg = message.swapcase()
print(msg)

Related Posts