Code-:
a=10
b=5
temp=a
a=b
b=temp
a=10
b=5
temp=a
a=b
b=temp
I am studying pythonPython and I stumbled upon the classic program-: The swapping programSwapping Program.
It is simple.:
temptemp
binds to aa
.
aa
binds to bb
.
bb
binds to temptemp
.
I can decode what is happening in memory as well. I will show it 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.