Python String swapcase() MethodPython Functions

Difficulty Level:
Difficulty Level:

The swapcase() method converts the uppercase letters of a string to lower case and the lowercase letters to upper case.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

str = "Jason is a famous actor in Hollywood.!!!"
print (str.swapcase())

str = "ABCabcABC"
print (str.swapcase())

Output:

jASON IS A FAMOUS ACTOR IN hOLLYWOOD.!!!
abcABCabc

Syntax

str.swapcase()

Parameters

The method doesn’t take any parameters.

Return Value

It returns the string where all uppercase characters are converted to lowercase, and lowercase characters are converted to uppercase.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us