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 Sets
Python Program to Count the Number of Each Vowel
Python print()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Java InputStream to String
Python List count()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Variables, Constants and Literals
Python Program to Solve Quadratic Equation
Python vars()
Python Program to Print all Prime Numbers in an Interval
Python String rpartition()
Python Dictionary setdefault()
Python Operator Overloading
Python bool()
String Set Queries
Python Program to Check if a Key is Already Present in a Dictionary
Python String find()
Array to String Conversions
Java – Generate Random String
Python Program to Compute all the Permutation of the String
Python Input, Output and Import
Python issubclass()
Python Program to Make a Simple Calculator
Python break and continue
Why String is Immutable in Java?
Python Set pop()
Python filter()
Python Program to Get the Class Name of an Instance
Python Program to Get a Substring of a String
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python abs()