Easy Tutorial
❮ Ref Math Lgamma Ref Math Pi ❯

Python3 swapcase() Method

Python3 Strings


Description

The swapcase() method in Python is used to convert the case of letters in a string, changing uppercase letters to lowercase and lowercase letters to uppercase.

Syntax

The syntax for the swapcase() method is:

str.swapcase();

Parameters

Return Value

Returns a new string with the case of letters swapped.

Example

The following example demonstrates the use of the swapcase() function:

#!/usr/bin/python

str = "tutorialpro!!!";
print ( str.swapcase() );

str = "tutorialpro!!!";
print ( str.swapcase() );

str = "abCDE--tutorialpro!!!";
print ( str.swapcase() );

The output of the above example is:

TUTORIALPRO!!!
TUTORIALPRO!!!
ABcde--tutorialpro!!!

Python3 Strings

❮ Ref Math Lgamma Ref Math Pi ❯