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 Split a List Into Evenly Sized Chunks
Python String isupper()
Python Dictionary get()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Check If Two Strings are Anagram
Python Program to Remove Punctuations From a String
Python Program to Print Hello world!
Python Data Structures and Algorithms - Benjamin Baka
Python memoryview()
Generate a String
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Global Keyword
Python String format_map()
Python vars()
Convert String to Byte Array and Reverse in Java
Python Program to Append to a File
Python Program to Find Numbers Divisible by Another Number
Python String zfill()
Python strftime()
Python Set pop()
Python complex()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Program to Shuffle Deck of Cards
Python Dictionary pop()
Python round()
Python Set difference_update()
Python while Loop
Python Program to Find Factorial of Number Using Recursion
Array to String Conversions
Deep Learning in Python - LazyProgrammer
Python String rpartition()
Python String join()