In Python, variable content swapping is a one-liner. In this video, we take a look at the classical way and then we see the Python-way of variable swapping.
We want to swap the contents of variables a and b. In the classical way, we take the content of the variable a to temp. Then we take the content of b to a. Now that the content of b is moved to a, we take the content of temp to b. The contents of a and b are swapped.
The Python way of doing the same thing is a, b is equal to b, a
The content of variables a and b are swapped.
Pretty cool! Is'nt it?
Dr. Shahriar Hossain and Dr. Monika Akbar
https://computing4all.com