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:
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python round()
Python Program to Check Leap Year
String Initialization in Java
Python Program to Find Sum of Natural Numbers Using Recursion
Python Program to Get the Full Path of the Current Working Directory
Python Multiple Inheritance
Python all()
Jackson – Marshall String to JsonNode
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Dictionary copy()
Python Set pop()
Python Program to Print all Prime Numbers in an Interval
Python open()
Python memoryview()
Deep Learning in Python - LazyProgrammer
Check if a String is a Palindrome in Java
Python Type Conversion and Type Casting
Python Program to Differentiate Between del, remove, and pop on a List
Python hash()
Python pow()
Python String encode()
Python Program to Find the Largest Among Three Numbers
Java InputStream to String
Python Program to Shuffle Deck of Cards
Python Program to Check If a List is Empty
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Remove Punctuations From a String
Array to String Conversions
Python Modules
Python Program to Display Fibonacci Sequence Using Recursion
Python Strings