Swapping is the most common this in logic designing. swapping in the OG's book.
x = 10
y = 20
temp = x
x = y
y = temp
print(x,y)
Output: 20 10
I agree that the old swapping technique works everytime,but it also increases the amount of code required. So let's learn some new swapping tricks.
Before going into the context lemme tell you the advantage of them,
- Integrating it into your code can make use of less instances than normally required.
- Improves logical thanking.
- Less wastage of resources.