Python String swapcase Method

The swapcase method in Python is used to change the case of each character in a string, transforming uppercase letters to lowercase and vice versa. This method does not take any arguments and will return a new string that reflects the case transformation.

Signature

Example

swapcase()

Parameters

No Parameter

Return

It returns a string.

Let us examine a few instances of the swapcase method to grasp its functionality.

Python String swapcase Method Example 1

A straightforward illustration of changing uppercase letters to lowercase can be accomplished through the utilization of the swapcase method.

Example

# Python String swapcase() method
# Declaring variable
str = "HELLO LOGICPRACTICE"
# Calling function
str2 = str.swapcase()
# Displaying result
print (str2)

Output:

Output

hello logicpractice

Python String swapcase Method Example 2

This illustration demonstrates the process of transforming lowercase letters into their uppercase equivalents.

Example

# Python String swapcase() method
# Declaring variable
str = "hello logicpractice"
# Calling function
str2 = str.swapcase()
# Displaying result
print (str2)

Output:

Output

HELLO LOGICPRACTICE

Python String swapcase Method Example 3

When the input string is formatted in camelcase, the result produced by this method will also adhere to the camelcase format. Every lowercase letter will be transformed into its uppercase counterpart, while all uppercase letters will be converted to lowercase.

Example

# Python String swapcase() method
# Declaring variable
str = "Hello World"
# Calling function
str2 = str.swapcase()
# Displaying result
print (str2)

Output:

Output

hELLO hELLO wORLD

Input Required

This code uses input(). Please provide values below: