sWAP cASE in Python | HackerRank Solution

Hello coders, today we will be solving sWAP cASE in Python Hacker Rank Solution.

sWAP cASE in Python - Hacker Rank Solution


You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.

For Example:

Www.HackerRank.com → wWW.hACKERrANK.COM
Pythonist 2 → pYTHONIST 2

Input Format

A single line containing a string S.


0 <= len(S) <= 1000

Output Format

Print the modified string S.

Sample Input 0

HackerRank.com presents "Pythonist 2".

Sample Output 0


Solution – sWAP cASE in Python – Hacker Rank Solution

def swap_case(s):
    num = ""
    for let in s:
        if let.isupper() == True:
    return num

if __name__ == '__main__':
    s = input()
    result = swap_case(s)

Disclaimer: The above Problem (sWAP cASE in Python) is generated by Hacker Rank but the Solution is provided by CodingBroz. This tutorial is only for Educational and Learning purposes.

1 thought on “sWAP cASE in Python | HackerRank Solution”

  1. Do we need to include constraints in the code to verify whether the length of the string satisfies the requirement 0 <= len(S) <= 1000?

Leave a Comment

Your email address will not be published. Required fields are marked *