Example: #1 - Swapping of two numbers using temporary variable
Python Input Screen
class SwapExample:
def __init__(self):
pass
def swapNumbers(self):
a = 3
b = 6
print("The value of a before swap is " + str(a))
print("The value of b before swap is " + str(b))
# Swapping of two numbers using temp variable
temp = a
a = b
b = temp
print("The value of a after swap is " + str(a))
print("The value of b after swap is " + str(b))
obj = SwapExample()
obj.swapNumbers()
Python Output Screen
The value of a before swap is 3
The value of b before swap is 6
The value of a after swap is 6
The value of b after swap is 3