Python logoPython/
PYL-R1712

Use `tuple` unpacking to swap variablesPYL-R1712

Major severityMajor
Anti-pattern categoryAnti-pattern

It is recommended not to use a temporary variable in order to swap variables. Using tuple unpacking to directly swap variables makes the intention more clear.

Bad practice

Not preferred:

temp = a
a = b
b = temp
a, b = b, a

swaps the values of a and b.