Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python swapcase() method

Python swapcase() method

Python Strings Python Strings


Description

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

Syntax

swapcase() Method syntax:



str.swapcase();

Parameters

Return Value

Returns the new string generated after the case conversion.

Example

The following example shows how to use the swapcase() function:

Example

#!/usr/bin/python

str

=

"

RUNOOB!!!

"

;

print

(

str

.

swapcase

(

)

)

;

str

=

"

runoob!!!

"

;

print

(

str

.

swapcase

(

)

)

;

str

=

"

abCDE--RuNOob!!!

"

;

print

(

str

.

swapcase

(

)

)

;

The output of the above example is:



runoob!!!

RUNOOB!!!

ABcde--rUnoOB!!!


Python Strings Python Strings