swapping case of a string in python code example

Example 1: python swapping characters in string

def swap(string, i, j):
    """
    Swapping between 2 given indices of a chars in a string
    :param string: string
    :param i: first index
    :param j: second index
    :return: new string with the swapped chars
    """
    string = list(string)
    string[i], string[j] = string[j], string[i]
    return ''.join(string)

# EXAMPLE
str = "example"
print(swap(str, 0, 1)) # print "xeample"

Example 2: swapping upper case and lower case string python

# swapcase() method 

string = "thE big BROWN FoX JuMPeD oVEr thE LAZY Dog"
print(string.swapcase()) 

>>> THe BIG brown fOx jUmpEd OveR THe lazy dOG