Table of Contents
The string swapcase() method converts all uppercase characters to lowercase and all lowercase characters to uppercase characters of the given string, and returns it.
The format of swapcase()
method is:
string.swapcase()
Note: Not necessarily, string.swapcase().swapcase() == string
1. String swapcase() Parameters()
swapcase()
method doesn’t take any parameters.
2. Return value from String swapcase()
swapcase()
method returns the string where all uppercase characters are converted to lowercase, and lowercase characters are converted to uppercase.
3. Example 1: Swap lowercase to uppercase and vice versa using swapcase()
# example string string = "THIS SHOULD ALL BE LOWERCASE." print(string.swapcase()) string = "this should all be uppercase." print(string.swapcase()) string = "ThIs ShOuLd Be MiXeD cAsEd." print(string.swapcase())
Output
this should all be lowercase. THIS SHOULD ALL BE UPPERCASE. tHiS sHoUlD bE mIxEd CaSeD.
Note: If you want to convert string to lowercase only, use lower(). Likewise, if you want to convert string to uppercase only, use upper().
Related posts:
Python Program to Convert Kilometers to Miles
Converting a List to String in Java
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Global, Local and Nonlocal variables
Python delattr()
Python Program to Find the Size (Resolution) of a Image
Python locals()
Python String encode()
Python Dictionary get()
Python List reverse()
Python Program to Append to a File
Python Program to Parse a String to a Float or Int
Python Set copy()
Python File I/O Operation
Python Program to Extract Extension From the File Name
Python Program to Check the File Size
Python Dictionary update()
Python min()
Python for Loop
Python Program to Find ASCII Value of Character
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Make a Simple Calculator
Python Strings
Map to String Conversion in Java
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Check Prime Number
Python Program to Print all Prime Numbers in an Interval
Python Program to Concatenate Two Lists
Converting a Stack Trace to a String in Java
Python Data Types
Python String isidentifier()
Python List pop()