Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to do swapping in python without sort function


# 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)
 
PREVIOUS NEXT
Tagged: #swapping #python #sort #function
ADD COMMENT
Topic
Name
9+4 =