Computer Science, asked by shuklaanubhav329, 4 months ago

Equation
Python Program to Swap Two Variables
Python Program​

Answers

Answered by rishikukreti39park9j
3

Answer:

a,b = b,a

Explanation:

Ok, so let's assume:

a = 1

b = 2

a, b = b, a

here "a" is interchanged with the value of "b", and Vice versa

Thank you

Answered by PreetiGupta2006
15

What is Swap?

It means to exchange .

For example : we generally change our seats in school just to sit beside our friend in school.

Similar is in python.

So let's cöde for this program:

a=int(input("Enter 1st number:"))

b=int(input("Enter 2nd number:"))

temp=a

a=b

b=temp

print("The value of 'a' after swapping is",a)

print("The value of 'b' after swapping is",b)

Output:

The value of 'a' after swapping is :12

The value of 'b' after swapping is :17

Note: The output will surely change if the user chooses any other number instead of the one provided in the image.

Attachments:
Similar questions