How to Use String swapcase() Method in PythonPython Basics


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.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us