Python String swapcase()

Python string swapcase() method is a built-in function that converts all uppercase characters into lowercase and all lowercase characters into uppercase characters of a given string and returns a new string.

swapcase() Syntax

The Syntax of swapcase() method is:


swapcase() Parameters

The swapcase() method doesn’t take any parameters.

swapcase() Return Value

The swapcase() method returns a copy of the string where all the uppercase characters are converted into lowercase characters and vice-versa.

In case the string has other than alphabets those characters will not be converted and returned as-is.

Example: Python Program to change the case of a given string

text1 = "pYTHON tUTORIALS"

text2 = "HELLO WORLD"

text3 = "welcome to itsmycode"

text4 ="12345!!!"


Python Tutorials
hello world
Note: If you want to convert given string into lowercase only it is recommended to use lower() method. Likewise, if you want to convert given string into uppercase only it is recommended to use upper() method.
Leave a Reply

Your email address will not be published.

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like
Menu Driven Program In Python

Menu Driven Program in Python

Introduction to Menu-Driven Program A menu driven program in Python is a program that takes input from a user by displaying a list of options and allows users to choose…
View Post
Python String Isprintable()

Python String isprintable()

Table of Contents Hide What are printable characters in Python?isprintable() Syntaxisprintable() Parametersisprintable() Return ValueExample 1: Working of isprintable() method Example 2: How to use isprintable() in real world? The Python…
View Post
Syntaxerror Unexpected Eof While Parsing

SyntaxError: unexpected EOF while parsing

Table of Contents Hide What is unexpected EOF while parsing error?Scenario 1 – Incomplete parameters may cause this kind of errors.Scenario 2: Incomplete functions along with statements, loops, try and…
View Post
Xor In Python

XOR in Python

XOR Operator in Python is also known as “exclusive or”  that compares two binary numbers bitwise if two bits are identical XOR outputs as 0 and when two bits are different then…
View Post
Python Divmod()

Python divmod()

Table of Contents Hide divmod() Syntax divmod() Parametersdivmod() Return ValueExample: How divmod() works in Python?Errors And Exceptions  The divmod() in Python is a built-in function that takes two numbers as input…
View Post