Skip to main content

swapcase()

The swapcase() method is a string method in Python that returns a new string with uppercase letters converted to lowercase and vice versa. It swaps the case of all letters in the given string.

Parameter Values

This function does not accept any parameters.

Return Values

The swapcase() method returns a new string with cased characters swapped.

How to Use swapcase() in Python

Example 1:

The swapcase() method returns a new string with uppercase characters converted to lowercase and vice versa.

text = 'Hello, World!' 
print(text.swapcase())
Example 2:

It does not modify the original string, but returns a new string with the swapped cases.

original_text = 'i LoVe PyThOn' 
swapped_text = original_text.swapcase() 
print(swapped_text)
Example 3:

The swapcase() method is useful for toggling the case of characters in a string.

user_input = input('Enter a string: ') 
modified_input = user_input.swapcase() 
print(modified_input)