×

Python String swapcase() method

Python String swapcase() method

The string.swapcase() method in Python returns a copy of the string with uppercase characters converted to lowercase and vice versa.

Syntax

string.swapcase()

Parameter

NA

Return

This method returns a copy of the string with uppercase characters converted to lowercase and vice versa.

Example 1

 # Python program explaining
 # the string.swapcase() method
 string="heLLo wORLd"
 # observe the original string 
 print("Actual String: ",string)
 # swaping the string i.e upper case to lower case or vice versa
 val = string.swapcase()
 # printing the swap cased string
 print("Uppercased string: ",val) 

Output

Actual String:  heLLo wORLd
Uppercased string:  HEllO WorlD

Example 2

 # Python program explaining
 # the string.swapcase() method
 string1="heLLo wORLd"
 # observe the original string 
 print ('Original String: ', string1 )
 print ('Converted String is = ', string1.swapcase()) 
 # passing special characters  
 string2 = 'mY#namE#Is#REEma#panDA'.swapcase() 
 print ('\nSecond Output for swapcase() method is = ', string2 )
 # passing integer values
 string3 = '98041'.swapcase() 
 print('\nFourth Output after swapcase() method is = ', string3 )  
 string4 = 'pyTHon\niS\neAsy\ntO\nLEARN'.swapcase() 
 print ('\nThird Output after swapcase() method is = ', string4) 

Output

 Original String:  heLLo wORLd
 Converted String is =  HEllO WorlD
 Second Output for swapcase() method is =  My#NAMe#iS#reeMA#PANda
 Fourth Output after swapcase() method is =  98041
 Third Output after swapcase() method is =  PYthON
 Is
 EaSY
 To
 learn 

Related Topics

GUI Calendar using PyQt5 in Python

GUI: One of the most significant factors that increased the usability of computer and digital technologies for common, less tech-savvy users is likely the development and widespread adoption of GUIs. GUIs...

3 minutes read.

How to Install Python

Python Installation Guide Step by Step Installing Python is quite simple and easy. In this tutorial, we will show stepwise procedure to install Python and set up the Python environment in different...

2 minutes read.

Python String strip() method

Python String strip() method The string. strip() method in Python removes any leading (spaces at the beginning) and trailing (spaces at the end) characters (space is the default leading character to...

1 minute read.

App Config Python

An XML file called App. Config serves as the document for any programme. In other terms, you can modify any configuration inside of it without going to edit the code...

7 minutes read.

Python if statement

Python if statement Decision making is an essential feature of any programming languages. Condition checking is the strength of decision making. Python provides many decision-making statements, such as: If statementIf-else statementelif statement if statement The if statement is...

2 minutes read.

Python String Negative Indexing

This page contains all the information how to use “Negative indexing“ in Python with the help of using slicing. What is an Index? An index is a numeric value, which is assigned...

3 minutes read.

Python Multiprocessing Processor

Python: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

4 minutes read.

Loan calculator using Tkinter in Python

Tkinter: Tkinter, part of all common Python distributions, is the de facto method for creating Graphical User Interfaces (GUIs) in Python. The only framework included in the Python standard library is...

4 minutes read.

Python - Binomial Distribution

Introduction Definition of the Binomial Distribution The method of counting how many instances of a specific event there have been is called the binomial distribution. It will outline the possible outcomes or...

4 minutes read.

Flutter with tensor flow in python

Python : Python is an object oriented programming language which is highly interpreted and is highly interactive. Python was created by Guido van Rossum in the year 1985 – 1990 .The...

3 minutes read.

How to Declare a Variable in Python?

The concept of constants and variables is something that we are studying right from our primary classes. We know that constants are the fixed values whereas variables are those whose...

4 minutes read.

Joint Plot in Python

Introduction to Joint plots: The joint plot is the finest approach to evaluate both the specific distribution of each variable and also the connection between the two variables. Three different plots make...

4 minutes read.

Python Generator

Python Generator: A Function is said to be a Python Generator that produces or generates a sequence of results. A Python Generator maintains its native state to work so that...

6 minutes read.

Python Tuple index() Method

Python Tuple index() Method The tuple.index() method of Python finds the first occurrence of the specified value and returns its index if the value is found else raises an exception if...

1 minute read.

Python String index() method

Python String index() method The string.index() method in Python finds the lower index of the first occurrence of the specified value or raise a ValueError if the substring is not found. Syntax index(sub[, start[, end]]) Parameter sub:...

2 minutes read.

Python program to count the number of a substring in a string

Python program to count the number of a substring in a string A part of the string is called a substring. This article explains the Python program to find how many...

1 minute read.

List Index out of Range Python for Loop

The List is generally used in Python to store multiple items or elements inside one single variable. The List is ordered in nature, the List can contain the elements inside...

3 minutes read.

Python Break Statement

In Python, loops are used to automate and repeat processes in an effective manner. However, there may be occasions when you wish to entirely exit the loop, skip an iteration,...

2 minutes read.

How to assign values to variables in Python and other languages?

Python makes it simple to construct variables. The value to be stored in the variable should then be written after a suitable name for the variable and the equality sign....

3 minutes read.

_dict_ in Python

An unordered collection of data values known as a dictionary can be used in Python to store data values similar to a map. Dictionaries can also store a key: value...

6 minutes read.