Top MNC interview question which will be very useful for beginners to crack the interview and for there future careers

test

Breaking

Post Top Ad

Your Ad Spot

Sunday, December 27, 2020

Swapping two numbers without using temp variable in Python

 Question:

Swapping two numbers without using temp variable in Python

Explanation:

We need to swap the two numbers without using third variable.

For Example:

                     A=6, B=7                    

                     Result:
                                A=7, B=6

Program:

def swap(num1,num2):
    num1 = num1+num2
    num2 = num1-num2
    num1 = num1-num2
    print(num1, num2)

Swap(6, 7)

                                                                ---------End---------

Post Top Ad

Your Ad Spot