HOME/Articles/

swap case (snippet)

Article Outline

Python example 'swap case'

Functions in program:

  • def swap_case(s):

swap case

Python beginners example: swap case

def swap_case(s):
    swapped = ""
    for i in range(len(s)):
        temp = s[i].upper()
        if (s[i] == temp):
            swapped += s[i].lower()
        else:
            swapped += s[i].upper()

    return swapped