Skip to main content
2 of 3
added 5 characters in body

How was swapping program born?

Code-:

a=10
b=5
temp=a
a=b
b=temp

I am studying python and I stumbled upon the classic program-: The swapping program.

It is simple.

temp binds to a.

a binds to b.

b binds to temp

I can decode what is happening in memory as well. I will show it here-:

enter image description here

But sadly, I can't wrap my head around how we got to this program? What was the problem solving part of this problem. How did we decide that this would be our program? What logic was used to build this program? The reason is simple while I might not come across swapping 3 variables, but if I learn the basics programs properly, I make sure that I learn the complex topics as well.