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 Input, Output and Import
Python Program to Make a Flattened List from Nested List
Python String upper()
APIs in Node.js vs Python - A Comparison
Python min()
Python delattr()
Reading an HTTP Response Body as a String in Java
Python Program to Print Hello world!
Python complex()
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Map to String Conversion in Java
Python strftime()
Python bytes()
Python format()
Python String islower()
Python Program to Count the Number of Each Vowel
Python property()
Python exec()
Python String rindex()
Python Program to Create a Countdown Timer
Python Program to Remove Duplicate Element From a List
Python Program to Get a Substring of a String
Python print()
Python List insert()
Python Program to Get File Creation and Modification Date
Python Program to Merge Two Dictionaries
Python String find()
Python Set union()
Python Errors and Built-in Exceptions
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Multiply Two Matrices
Python Anonymous / Lambda Function