Swap three variables without using temporary variable | Assign c ' s ▁ value ▁ to ▁ a , ▁ a ' s value to b and b 's value to c. ; Store XOR of all in a ; After this , b has value of a [ 0 ] ; After this , c has value of b ; After this , a [ 0 ] has value of c ; Driver code ; Calling Function
def swapThree ( a , b , c ) : NEW_LINE INDENT a [ 0 ] = a [ 0 ] ^ b [ 0 ] ^ c [ 0 ] NEW_LINE b [ 0 ] = a [ 0 ] ^ b [ 0 ] ^ c [ 0 ] NEW_LINE c [ 0 ] = a [ 0 ] ^ b [ 0 ] ^ c [ 0 ] NEW_LINE a [ 0 ] = a [ 0 ] ^ b [ 0 ] ^ c [ 0 ] NEW_LINE DEDENT a , b , c = [ 10 ] , [ 20 ] , [ 30 ] NEW_LINE print ( " Before ▁ swapping ▁ a ▁ = ▁ " , a [ 0 ] , " , ▁ b ▁ = ▁ " , b [ 0 ] , " , ▁ c ▁ = ▁ " , c [ 0 ] ) NEW_LINE swapThree ( a , b , c ) NEW_LINE print ( " After ▁ swapping ▁ a ▁ = ▁ " , a [ 0 ] , " , ▁ b ▁ = ▁ " , b [ 0 ] , " , ▁ c ▁ = ▁ " , c [ 0 ] ) NEW_LINE