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:
Deep Learning with Python - Francois Cholletf
Python Program to Generate a Random Number
Python Operators
Python Set difference_update()
Python Program to Find Numbers Divisible by Another Number
Map to String Conversion in Java
Java InputStream to String
Python round()
Python Custom Exceptions
Python super()
Python Dictionary values()
Java InputStream to String
Python Program to Make a Flattened List from Nested List
Python Program to Print the Fibonacci sequence
Intelligent Projects Using Python - Santanu Pattanayak
Python str()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python List Comprehension
Python sum()
Python callable()
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python if...else Statement
Python Program to Display Powers of 2 Using Anonymous Function
Python print()
Python filter()
Python Program to Delete an Element From a Dictionary
Python Program to Extract Extension From the File Name
Python Program to Remove Punctuations From a String
Python Strings
Python Dictionary keys()
How to Get Started With Python?
Python Shallow Copy and Deep Copy