Python swapcase() method
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
- NA.
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!!!
"
;
(
str
.
swapcase
(
)
)
;
str
=
"
runoob!!!
"
;
(
str
.
swapcase
(
)
)
;
str
=
"
abCDE--RuNOob!!!
"
;
(
str
.
swapcase
(
)
)
;
The output of the above example is:
runoob!!!
RUNOOB!!!
ABcde--rUnoOB!!!
Python Strings