SWAP TWO VARIABLES

 SWAP TWO VARIABLES

The swap_without_temp function swaps the values of two variables a and b without using a temporary variable.

def swap_without_temp(a, b):

    return b, a

 


if __name__=="__main__":

    result = swap_without_temp(5, 10)

    print(f"After swapping: a = {result[0]}, b = {result[1]}")

Output:
After swapping: a = 10, b = 5

Comments

Popular posts from this blog

TRANSPOSE OF A MATRIX

FIND THE DAY OF YEAR

CHECK IF DATE IS VALID