Swap Variable¶
Sourcery refactoring id: swap-variable
¶
Description:¶
Swap variable values with tuple assignment
Before:¶
temp = a
a = b
b = temp
After:¶
a, b = b, a
Explanation:¶
When trying to swap the values held by two variables, we may avoid using an extra temporary variable unnecessarily by employing Python's tuple assignment. As a consequence of this refactoring, the code is not only more concise but also reflects its intention more clearly.