Swapping of two variable by using third variable in python by R4R Team

What is swapping ?


Exchange the value of the two variable which is already exist is called swapping.

Example -

Before swapping
a=10
b=20
After swapping
a=20
b=10

program-

print("Enter first value")
a=input()
print("Enter second value")
b=input()
print("Before swapping -")
print(a,b)
t=a
a=b
b=t
print("After swapping -")
print(a,b)


output -

Enter first value
3
Enter second value
4
Before swapping -
3 4
After swapping -
4 3

Enter first value
#
Enter second value
@
Before swapping -
# @
After swapping -
@ #


-In this program ,we use third variable to swap the two values.the main code is t=a,a=b,b=t which is responsible to swap the value.
Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!