Or, in Python
a, b = b, a
Or Rust: (a, b) = (b, a); a, b = b, a
Or Rust: (a, b) = (b, a); import dis
def swap(a, b):
a, b = b, a
return a
dis.dis(swap)
Output: 4 0 LOAD_FAST 1 (b)
2 LOAD_FAST 0 (a)
4 ROT_TWO
6 STORE_FAST 0 (a)
8 STORE_FAST 1 (b)
5 10 LOAD_FAST 0 (a)
12 RETURN_VALUE
Implementation of ROT_TWO
https://github.com/python/cpython/blob/bc85eb7a4f16e9e2b6fb7...Express your actual intent, if your chosen language has a "swap" intrinsic, use it, if not write the swap in a natural and idiomatic way, and let other people do the lifting.
And then the cpu is doing something under the hood to do whatever the assembly code thought it said.
std::tie(a, b) = std::tuple(b, a); std::swap(a, b);