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.

Live Demo
#!/usr/bin/python

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

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

When we run above program, it produces following result −

THIS IS STRING EXAMPLE....WOW!!!
this is string example....wow!!!

python_strings.htm

Advertisements