

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to swap case of English word
Suppose we have a string with English letters. We have to swap the case of the letters. So uppercase will be converted to lower and lowercase converted to upper.
So, if the input is like s = "PrograMMinG", then the output will be pROGRAmmINg
To solve this, we will follow these steps −
- ret := blank string
- for each letter in s, do
- if letter is in uppercase, then
- ret := ret concatenate lower case equivalent of letter
- otherwise,
- ret := ret concatenate upper case equivalent of letter
- if letter is in uppercase, then
- return ret
Example
Let us see the following implementation to get better understanding
def solve(s): ret = '' for letter in s: if letter.isupper(): ret += letter.lower() else: ret += letter.upper() return ret s = "PrograMMinG" print(solve(s))
Input
"PrograMMinG"
Output
pROGRAmmINg
- Related Questions & Answers
- Java Program to swap the case of a String
- Java program to display English alphabets
- Program to swap string characters pairwise in Python
- Java Program to Swap Pair of Characters
- Integer to English Words in Python
- Python program to find word score from list of words
- Python Program to Swap the First and Last Value of a List
- Integer to English Words in Python Programming
- How to extract each (English) word from a string using regular expression in Java?
- Python program to count occurrences of a word in a string
- Program to find length of longest diminishing word chain in Python?
- C++ program to read file word by word?
- Program to swap nodes in a linked list in Python
- Program to minimize hamming distance after swap operations in Python
- Java program to swap two integers
Advertisements