Python swapcase() method Example
text1 = "pYTHON tUTORIALS"
print(text1.swapcase())
text2 = "HELLO WORLD"
print(text2.swapcase())
text3 = "welcome to itsmycode"
print(text3.swapcase())
text4 ="12345!!!"
print(text4.swapcase())
a=5
b=10
a,b=b,a #swapped
def swap0(s1, s2):
assert type(s1) == list and type(s2) == list
tmp = s1[:]
s1[:] = s2
s2[:] = tmp
# However, the easier and better way to do a swap in Python is simply:
s1, s2 = s2, s1
a = 10
b = 20
print("not swiped value of a is",a)
print("not swiped value of b is",b)
stored_value = a
a = b
b = stored_value
print("swiped value of a is",a)
print("swiped value of b is",b)
# Python program to swap two variables
x = 5
y = 10
# To take inputs from the user
#x = input('Enter value of x: ')
#y = input('Enter value of y: ')
# create a temporary variable and swap the values
temp = x
x = y
y = temp
print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))
# swapcase() method
string = "thE big BROWN FoX JuMPeD oVEr thE LAZY Dog"
print(string.swapcase())
>>> THe BIG brown fOx jUmpEd OveR THe lazy dOG
t = "Mr.Brown"
nt = t.swapcase()
print(nt)