In Python is
a,b = b,a
more efficient than
temp = a
a = b
b = temp
? How does that it work internally?
It's trivially faster as an implementation detail, but not enough to make a meaningful difference in most programs. It's faster because it avoids a STORE/LOAD pair of operations in favor of a ROT_TWO instruction, which is used after loading both source variables onto the program stack, to flip the order of the top two elements of the stack before STOREing back normally.
As noted, the speed up is trivial (in a few trials, the swap was faster than the explicit temporary, but only by a matter of single digit nanoseconds, which almost never matters), but it's cleaner to read the obvious swap, so people tend to prefer it when it's needed.
For the internals, the dis module is helpful:
>>> import dis
>>> dis.dis('a, b = b, a')
1 0 LOAD_NAME 0 (b)
2 LOAD_NAME 1 (a)
4 ROT_TWO
6 STORE_NAME 1 (a)
8 STORE_NAME 0 (b)
10 LOAD_CONST 0 (None)
12 RETURN_VALUE
>>> dis.dis('temp = a; a = b; b = temp')
1 0 LOAD_NAME 0 (a)
2 STORE_NAME 1 (temp)
4 LOAD_NAME 2 (b)
6 STORE_NAME 0 (a)
8 LOAD_NAME 1 (temp)
10 STORE_NAME 2 (b)
12 LOAD_CONST 0 (None)
14 RETURN_VALUE
You can see that the swap takes one fewer bytecode instructions, as well as executing more of the same instruction in a row (which may help cache utilization a tiny bit). The exact instructions differ based on where you execute it (_NAME might be _FAST or _GLOBAL or the like), so there might be more performance gains to be had when the instructions are more expensive (my microbenchmark was for function locals which use _FAST instructions that have the least overhead; running in global scope would probably make swapping a titch faster relatively speaking). But again, it's all trivial in the face of the choice of shorter, cleaner code vs. longer, uglier code.