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 *args and **kwargs
Python set()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Java String to InputStream
Python Program to Check if a Number is Positive, Negative or 0
Python Set symmetric_difference_update()
Python Program to Merge Two Dictionaries
Python Errors and Built-in Exceptions
Python List count()
Python Program to Create Pyramid Patterns
Python @property decorator
Python String title()
Python Sets
Python Iterators
How to Get Started With Python?
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Program to Check If Two Strings are Anagram
Python len()
Jackson – Marshall String to JsonNode
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python help()
Python String replace()
Python Program to Convert String to Datetime
Python id()
Python Directory and Files Management
Python Program to Find the Sum of Natural Numbers
Python Tuple
Python Program to Find HCF or GCD
Python Set clear()
Python Program to Find the Factors of a Number
Most commonly used String methods in Java
Python map()