# Python3 code to swap using XOR
x = 10
y = 5
# Code to swap 'x' and 'y'
x = x ^ y; # x now becomes 15 (1111)
y = x ^ y; # y becomes 10 (1010)
x = x ^ y; # x becomes 5 (0101)
print ("After Swapping: x = ", x, " y =", y)
# Python3 program to
# swap two numbers
# without using
# temporary variable
x = 10
y = 5
# code to swap
# 'x' and 'y'
# x now becomes 50
x = x * y
# y becomes 10
y = x // y;
# x becomes 5
x = x // y;
print("After Swapping: x =",
x, " y =", y);
def swap(xp, yp):
xp[0] = xp[0] ^ yp[0]
yp[0] = xp[0] ^ yp[0]
xp[0] = xp[0] ^ yp[0]
# Driver code
x = [10]
swap(x, x)
print("After swap(&x, &x): x = ", x[0])
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)