Python String swapcase() Method

Advertisements


Description

The method swapcase() returns a copy of the string in which all the case-based characters have had their case swapped.

Syntax

Following is the syntax for swapcase() method:

str.swapcase();

Parameters

  • NA

Return Value

This method returns a copy of the string in which all the case-based characters have had their case swapped.

Example

The following example shows the usage of swapcase() method.

#!/usr/bin/python

str = "this is string example....wow!!!";
print str.swapcase();

str = "THIS IS STRING EXAMPLE....WOW!!!";
print str.swapcase();

Let us compile and run the above program, this will produce the following result:

this is string example....wow!!!



Advertisements
Advertisements