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 frozenset()
Java – String to Reader
String Hashing
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Closures
Python Program to Sort a Dictionary by Value
Python Program to Remove Duplicate Element From a List
Python String join()
Python Set remove()
Python String rstrip()
Python Program to Measure the Elapsed Time in Python
Python List extend()
Python Program to Add Two Numbers
Python hasattr()
Python List append()
Python Program to Print Hello world!
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python String index()
Python Strings
Python Program to Print all Prime Numbers in an Interval
Python Program to Differentiate Between type() and isinstance()
Java String to InputStream
Jackson – Marshall String to JsonNode
Python Set union()
Python strptime()
Python List Comprehension
Python complex()
Python Program to Convert Two Lists Into a Dictionary
Java Program to Permute All Letters of an Input String
Python List pop()
Python Program to Merge Two Dictionaries
Python len()